Skip to content

Commit 3a6253b

Browse files
authored
Merge pull request #243 from vizzuhq/remove_catches
Remove catch clauses
2 parents fd6b6cf + ca83fab commit 3a6253b

File tree

6 files changed

+64
-79
lines changed

6 files changed

+64
-79
lines changed

src/apps/weblib/interface.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,10 @@ const char *Interface::getChartValue(const char *path)
106106

107107
void Interface::setChartValue(const char *path, const char *value)
108108
{
109-
try {
110-
if (chart) {
111-
chart->getConfig().setParam(path, value);
112-
}
113-
else
114-
throw std::logic_error("No chart exists");
115-
}
116-
catch (std::exception &e) {
117-
throw std::logic_error(
118-
std::string(path) + "/" + value + ": " + e.what());
119-
}
109+
if (chart)
110+
chart->getConfig().setParam(path, value);
111+
else
112+
throw std::logic_error("No chart exists");
120113
}
121114

122115
void Interface::relToCanvasCoords(double rx,

src/base/style/sheet.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ template <class Params> class Sheet
7171
{
7272
if (!hasParam(path))
7373
throw std::logic_error(
74-
"non-existent style parameter: " + std::string(path));
74+
path + "/" + value
75+
+ ": non-existent style parameter");
7576

7677
Style::ParamRegistry<Params>::instance().visit(path,
7778
[&](auto &p)
@@ -104,20 +105,20 @@ template <class Params> class Sheet
104105

105106
if (count == 0)
106107
throw std::logic_error(
107-
"non-existent style parameter(s): "
108-
+ std::string(path) + ".*");
108+
path + ".*: non-existent style parameter(s)");
109109
}
110110
else
111111
throw std::logic_error(
112-
"non-existent style parameter: " + std::string(path));
112+
path + "/" + value
113+
+ ": non-existent style parameter");
113114
}
114115

115116
static std::string getParam(Params &params,
116117
const std::string &path)
117118
{
118119
if (!hasParam(path))
119120
throw std::logic_error(
120-
"non-existent style parameter: " + std::string(path));
121+
path + ": non-existent style parameter");
121122

122123
std::string res;
123124
Style::ParamRegistry<Params>::instance().visit(path,

src/base/util/eventdispatcher.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ bool EventDispatcher::Event::invoke(Params &&params)
5757
{
5858
params.event = std::const_pointer_cast<Event>(shared_from_this());
5959
for (auto &handler : handlers) {
60-
try {
61-
params.handler = handler.first;
62-
currentlyInvoked = params.handler;
63-
handler.second(params);
64-
currentlyInvoked = 0;
65-
if (params.stopPropagation) break;
66-
}
67-
catch (...) {
68-
}
60+
params.handler = handler.first;
61+
currentlyInvoked = params.handler;
62+
handler.second(params);
63+
currentlyInvoked = 0;
64+
if (params.stopPropagation) break;
6965
}
7066
for (auto &item : handlersToRemove) detach(item.first);
7167
return !params.preventDefault;

src/chart/options/config.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void Config::setParam(const std::string &path,
3535
auto it = accessors.find(path);
3636
if (it == accessors.end())
3737
throw std::logic_error(
38-
"invalid config parameter: " + path);
38+
path + "/" + value + ": invalid config parameter");
3939
it->second.set(*setter, value);
4040
}
4141
}
@@ -49,7 +49,7 @@ std::string Config::getParam(const std::string &path) const
4949
auto it = accessors.find(path);
5050
if (it == accessors.end())
5151
throw std::logic_error(
52-
"invalid config parameter: " + path);
52+
path + ": invalid config parameter");
5353
return it->second.get(setter->getOptions());
5454
}
5555
}
@@ -118,14 +118,16 @@ void Config::setChannelParam(const std::string &path,
118118
Conv::parse<OptionalChannelExtrema>(value));
119119
}
120120
else
121-
throw std::logic_error("invalid range setting");
121+
throw std::logic_error(
122+
path + "/" + value + ": invalid range setting");
122123
}
123124
else if (property == "labelLevel") {
124125
setter->setLabelLevel(id, Conv::parse<uint64_t>(value));
125126
}
126127
else
127128
throw std::logic_error(
128-
"invalid channel parameter: " + property);
129+
path + "/" + value
130+
+ ": invalid channel parameter: " + property);
129131
}
130132

131133
std::string Config::getChannelParam(const std::string &path) const
@@ -136,9 +138,7 @@ std::string Config::getChannelParam(const std::string &path) const
136138

137139
auto &channel = setter->getOptions().getChannels().at(id);
138140

139-
if (property == "title") {
140-
return Conv::toString(channel.title);
141-
}
141+
if (property == "title") { return Conv::toString(channel.title); }
142142
else if (property == "axis") {
143143
return Conv::toString(channel.axisLine);
144144
}
@@ -175,14 +175,13 @@ std::string Config::getChannelParam(const std::string &path) const
175175
}
176176
else
177177
throw std::logic_error(
178-
"invalid range parameter: " + path);
178+
path + ": invalid range parameter");
179179
}
180180
else if (property == "labelLevel") {
181181
return Conv::toString(channel.labelLevel);
182182
}
183183
else
184-
throw std::logic_error(
185-
"invalid channel parameter: " + property);
184+
throw std::logic_error(path + ": invalid channel parameter");
186185
}
187186

188187
std::list<std::string> Config::listChannelParams()
@@ -236,7 +235,7 @@ Config::Accessors Config::initAccessors()
236235
[](const Options &options)
237236
{
238237
auto cs{options.polar ? CoordSystem::polar
239-
: CoordSystem::cartesian};
238+
: CoordSystem::cartesian};
240239
return Conv::toString(cs);
241240
},
242241
.set =
@@ -263,8 +262,7 @@ Config::Accessors Config::initAccessors()
263262
{.get =
264263
[](const Options &options)
265264
{
266-
return Conv::toString(
267-
options.shapeType);
265+
return Conv::toString(options.shapeType);
268266
},
269267
.set =
270268
[](OptionsSetter &setter, const std::string &value)
@@ -276,9 +274,8 @@ Config::Accessors Config::initAccessors()
276274
{.get =
277275
[](const Options &options)
278276
{
279-
auto res(options.horizontal
280-
? Orientation::horizontal
281-
: Orientation::vertical);
277+
auto res(options.horizontal ? Orientation::horizontal
278+
: Orientation::vertical);
282279
return Conv::toString(res);
283280
},
284281
.set =
@@ -293,8 +290,7 @@ Config::Accessors Config::initAccessors()
293290
{.get =
294291
[](const Options &options)
295292
{
296-
auto res(options.sorted ? Sort::byValue
297-
: Sort::none);
293+
auto res(options.sorted ? Sort::byValue : Sort::none);
298294
return Conv::toString(res);
299295
},
300296
.set =
@@ -308,7 +304,8 @@ Config::Accessors Config::initAccessors()
308304
{.get =
309305
[](const Options &options)
310306
{
311-
return Conv::toString(static_cast<bool>(options.reverse));
307+
return Conv::toString(
308+
static_cast<bool>(options.reverse));
312309
},
313310
.set =
314311
[](OptionsSetter &setter, const std::string &value)
@@ -325,14 +322,16 @@ Config::Accessors Config::initAccessors()
325322
.set =
326323
[](OptionsSetter &setter, const std::string &value)
327324
{
328-
setter.setAlign(Conv::parse<Base::Align::Type>(value));
325+
setter.setAlign(
326+
Conv::parse<Base::Align::Type>(value));
329327
}}});
330328

331329
res.insert({"split",
332330
{.get =
333331
[](const Options &options)
334332
{
335-
return Conv::toString(static_cast<bool>(options.splitted));
333+
return Conv::toString(
334+
static_cast<bool>(options.splitted));
336335
},
337336
.set =
338337
[](OptionsSetter &setter, const std::string &value)
@@ -350,7 +349,8 @@ Config::Accessors Config::initAccessors()
350349
.set =
351350
[](OptionsSetter &setter, const std::string &value)
352351
{
353-
setter.showTooltip(Conv::parse<std::optional<int>>(value));
352+
setter.showTooltip(
353+
Conv::parse<std::optional<int>>(value));
354354
}}});
355355

356356
return res;

src/data/datacube/datacube.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,30 @@ MultiIndex DataCube::getIndex(const TableRow<double> &row,
7979

8080
DimIndex DataCube::getDimBySeries(SeriesIndex index) const
8181
{
82-
try {
83-
return dimBySeries.at(index);
84-
}
85-
catch (...) {
86-
throw std::logic_error(
87-
"internal error, table column is not in data cube");
88-
}
82+
if (auto it = dimBySeries.find(index);
83+
it != std::end(dimBySeries)) [[likely]]
84+
return it->second;
85+
86+
throw std::logic_error(
87+
"internal error, table column is not in data cube");
8988
}
9089

9190
SeriesIndex DataCube::getSeriesByDim(DimIndex index) const
9291
{
93-
try {
94-
return seriesByDim.at(index);
95-
}
96-
catch (...) {
97-
throw std::logic_error(
98-
"internal error, dimension index out of range");
99-
}
92+
if (seriesByDim.size() > index) [[likely]]
93+
return seriesByDim[index];
94+
95+
throw std::logic_error(
96+
"internal error, dimension index out of range");
10097
}
10198

10299
SeriesIndex DataCube::getSeriesBySubIndex(SubCellIndex index) const
103100
{
104-
try {
105-
return seriesBySubIndex.at(index);
106-
}
107-
catch (...) {
108-
throw std::logic_error(
109-
"internal error, sub-cell index out of range");
110-
}
101+
if (seriesBySubIndex.size() > index) [[likely]]
102+
return seriesBySubIndex[index];
103+
104+
throw std::logic_error(
105+
"internal error, sub-cell index out of range");
111106
}
112107

113108
SubSliceIndex DataCube::subSliceIndex(const SeriesList &colIndices,

src/data/table/columninfo.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ double ColumnInfo::registerValue(const std::string &value)
143143
return val;
144144
}
145145

146-
try {
147-
double val = std::stod(value);
148-
range.include(val);
149-
if (!Math::Floating(val).isInteger())
150-
contiType = ContiType::Float;
151-
152-
return val;
153-
}
154-
catch (...) {
146+
const char* strVal = value.c_str();
147+
char* eof;
148+
double val = std::strtod(strVal, &eof);
149+
if (eof == strVal)
155150
throw std::logic_error(
156-
"internal error, cell should be numeric: " + value);
157-
}
151+
"internal error, cell should be numeric: " + value);
152+
153+
range.include(val);
154+
if (!Math::Floating(val).isInteger())
155+
contiType = ContiType::Float;
156+
157+
return val;
158158
} break;
159159

160160
case Type::dimension: {

0 commit comments

Comments
 (0)