Skip to content

Commit 308cb1f

Browse files
committed
Improve exceptions messages
1 parent fd5b1e2 commit 308cb1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+434
-310
lines changed

include/packingsolver/box/instance.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ struct ItemType
119119
return box.z;
120120
} default: {
121121
throw std::invalid_argument(
122-
"Incorrect rotation value: '"
122+
FUNC_SIGNATURE + ": "
123+
"incorrect rotation value: '"
123124
+ std::to_string(rotation) + "'");
124125
}
125126
}
@@ -142,7 +143,8 @@ struct ItemType
142143
return box.x;
143144
} default: {
144145
throw std::invalid_argument(
145-
"Incorrect rotation value: '"
146+
FUNC_SIGNATURE + ": "
147+
"incorrect rotation value: '"
146148
+ std::to_string(rotation) + "'");
147149
}
148150
}
@@ -165,7 +167,8 @@ struct ItemType
165167
return box.y;
166168
} default: {
167169
throw std::invalid_argument(
168-
"Incorrect rotation value: '"
170+
FUNC_SIGNATURE + ": "
171+
"incorrect rotation value: '"
169172
+ std::to_string(rotation) + "'");
170173
}
171174
}

include/packingsolver/boxstacks/instance.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ struct ItemType
156156
return box.z;
157157
} default: {
158158
throw std::invalid_argument(
159-
"Incorrect rotation value: '"
160-
+ std::to_string(rotation) + "'");
159+
FUNC_SIGNATURE + ": "
160+
"incorrect rotation value; "
161+
"rotation: '" + std::to_string(rotation) + "'");
161162
}
162163
}
163164
}
@@ -179,8 +180,9 @@ struct ItemType
179180
return box.x;
180181
} default: {
181182
throw std::invalid_argument(
182-
"Incorrect rotation value: '"
183-
+ std::to_string(rotation) + "'");
183+
FUNC_SIGNATURE + ": "
184+
"incorrect rotation value; "
185+
"rotation: '" + std::to_string(rotation) + "'");
184186
}
185187
}
186188
}
@@ -202,8 +204,9 @@ struct ItemType
202204
return box.y;
203205
} default: {
204206
throw std::invalid_argument(
205-
"Incorrect rotation value: '"
206-
+ std::to_string(rotation) + "'");
207+
FUNC_SIGNATURE + ": "
208+
"incorrect rotation value; "
209+
"rotation: '" + std::to_string(rotation) + "'");
207210
}
208211
}
209212
}

src/algorithms/sequential_value_correction.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ SequentialValueCorrectionOutput<Instance, Solution> sequential_value_correction(
259259
}
260260
if (number_of_copies < 1) {
261261
throw std::logic_error(
262+
FUNC_SIGNATURE + "; "
262263
"number_of_copies: " + std::to_string(number_of_copies) + ".");
263264
}
264265

@@ -371,6 +372,7 @@ SequentialValueCorrectionOutput<Instance, Solution> sequential_value_correction(
371372
}
372373
if (number_of_copies < 1) {
373374
throw std::logic_error(
375+
FUNC_SIGNATURE + "; "
374376
"number_of_copies: " + std::to_string(number_of_copies) + ".");
375377
}
376378

src/box/algorithm_formatter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ void AlgorithmFormatter::print_header()
125125
break;
126126
} default: {
127127
std::stringstream ss;
128-
ss << "Problem type '" << Instance::type() << "' does not support objective \""
128+
ss << FUNC_SIGNATURE << ": "
129+
<< "problem type '" << Instance::type() << "' does not support objective \""
129130
<< instance_.objective() << "\"";
130131
throw std::logic_error(ss.str());
131132
}
@@ -198,7 +199,8 @@ void AlgorithmFormatter::print(
198199
break;
199200
} default: {
200201
std::stringstream ss;
201-
ss << "Problem type '" << Instance::type() << "' does not support objective \""
202+
ss << FUNC_SIGNATURE << ": "
203+
<< "problem type '" << Instance::type() << "' does not support objective \""
202204
<< instance_.objective() << "\"";
203205
throw std::logic_error(ss.str());
204206
}

src/box/branching_scheme.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ BranchingScheme::Node BranchingScheme::child_tmp(
269269
Volume item_volume = xj * yj * zj;
270270
if (insertion.z + zj > zi) {
271271
throw std::runtime_error(
272+
FUNC_SIGNATURE + "; "
272273
"insertion.z: " + std::to_string(insertion.z)
273274
+ "; zj: " + std::to_string(zj)
274275
+ "; zi: " + std::to_string(zi)
@@ -698,7 +699,8 @@ bool BranchingScheme::better(
698699
return node_2->profit < node_1->profit;
699700
} default: {
700701
std::stringstream ss;
701-
ss << "Branching scheme 'box::BranchingScheme'"
702+
ss << FUNC_SIGNATURE << ": "
703+
<< "Branching scheme 'box::BranchingScheme' "
702704
<< "does not support objective '" << instance().objective() << "'.";
703705
throw std::logic_error(ss.str());
704706
return false;
@@ -752,7 +754,8 @@ bool BranchingScheme::bound(
752754
return b >= node_2->xe_max;
753755
} default: {
754756
std::stringstream ss;
755-
ss << "Branching scheme 'box::BranchingScheme'"
757+
ss << FUNC_SIGNATURE << ": "
758+
<< "branching scheme 'box::BranchingScheme' "
756759
<< "does not support objective '" << instance().objective() << "'.";
757760
throw std::logic_error(ss.str());
758761
return false;

src/box/branching_scheme.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ class BranchingScheme
392392
} case Direction::Z: {
393393
return instance_flipper_z_.flipped_instance();
394394
} case Direction::Any: {
395-
throw std::invalid_argument("");
395+
throw std::invalid_argument(FUNC_SIGNATURE);
396396
return instance_;
397397
}
398398
}
399-
throw std::invalid_argument("");
399+
throw std::invalid_argument(FUNC_SIGNATURE);
400400
return instance_;
401401
}
402402

@@ -410,7 +410,7 @@ class BranchingScheme
410410
} else if (v == 0) {
411411
return Direction::Z;
412412
}
413-
throw std::logic_error("");
413+
throw std::logic_error(FUNC_SIGNATURE);
414414
return Direction::X;
415415
}
416416

@@ -424,7 +424,7 @@ class BranchingScheme
424424
} else if (v == 0) {
425425
return instance_flipper_z_.flipped_instance();
426426
}
427-
throw std::logic_error("");
427+
throw std::logic_error(FUNC_SIGNATURE);
428428
return instance_;
429429
}
430430

src/box/instance.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ void Instance::write_item_types(
202202
std::ofstream file(items_path);
203203
if (!file.good()) {
204204
throw std::runtime_error(
205-
"Unable to open file \"" + items_path + "\".");
205+
FUNC_SIGNATURE + ": "
206+
"unable to open file \"" + items_path + "\".");
206207
}
207208
file << "ID,"
208209
"X,"
@@ -234,7 +235,8 @@ void Instance::write_bin_types(
234235
std::ofstream file(bins_path);
235236
if (!file.good()) {
236237
throw std::runtime_error(
237-
"Unable to open file \"" + bins_path + "\".");
238+
FUNC_SIGNATURE + ": "
239+
"unable to open file \"" + bins_path + "\".");
238240
}
239241
file << "ID,"
240242
"X,"
@@ -266,7 +268,8 @@ void Instance::write_parameters(
266268
std::ofstream file(parameters_path);
267269
if (!file.good()) {
268270
throw std::runtime_error(
269-
"Unable to open file \"" + parameters_path + "\".");
271+
FUNC_SIGNATURE + ": "
272+
"unable to open file \"" + parameters_path + "\".");
270273
}
271274
file
272275
<< "NAME,VALUE" << std::endl

src/box/instance_builder.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,44 @@ BinTypeId InstanceBuilder::add_bin_type(
2323
{
2424
if (x <= 0) {
2525
throw std::invalid_argument(
26-
"packingsolver::box::InstanceBuilder::add_bin_type: "
26+
FUNC_SIGNATURE + ": "
2727
"bin 'x' must be > 0; "
2828
"x: " + std::to_string(x) + ".");
2929
}
3030
if (y <= 0) {
3131
throw std::invalid_argument(
32-
"packingsolver::box::InstanceBuilder::add_bin_type: "
32+
FUNC_SIGNATURE + ": "
3333
"bin 'y' must be > 0; "
3434
"y: " + std::to_string(y) + ".");
3535
}
3636
if (z <= 0) {
3737
throw std::invalid_argument(
38-
"packingsolver::box::InstanceBuilder::add_bin_type: "
38+
FUNC_SIGNATURE + ": "
3939
"bin 'z' must be > 0; "
4040
"z: " + std::to_string(z) + ".");
4141
}
4242
if (cost <= 0 && cost != -1) {
4343
throw std::invalid_argument(
44-
"packingsolver::box::InstanceBuilder::add_bin_type: "
44+
FUNC_SIGNATURE + ": "
4545
"bin 'cost' must be > 0 (or == -1); "
4646
"cost: " + std::to_string(cost) + ".");
4747
}
4848
if (copies_min < 0) {
4949
throw std::invalid_argument(
50-
"packingsolver::box::InstanceBuilder::add_bin_type: "
50+
FUNC_SIGNATURE + ": "
5151
"bin 'copies_min' must be >= 0; "
5252
"copies_min: " + std::to_string(copies_min) + ".");
5353
}
5454
if (copies != -1) {
5555
if (copies <= 0) {
5656
throw std::invalid_argument(
57-
"packingsolver::box::InstanceBuilder::add_bin_type: "
57+
FUNC_SIGNATURE + ": "
5858
"bin 'copies' must be > 0 (or == -1); "
5959
"copies: " + std::to_string(copies) + ".");
6060
}
6161
if (copies_min > copies) {
6262
throw std::invalid_argument(
63-
"packingsolver::box::InstanceBuilder::add_bin_type: "
63+
FUNC_SIGNATURE + ": "
6464
"bin 'copies_min' must be <= 'copies'; "
6565
"copies: " + std::to_string(copies) + "; "
6666
"copies_min: " + std::to_string(copies_min) + ".");
@@ -84,7 +84,7 @@ void InstanceBuilder::set_bin_type_maximum_weight(
8484
{
8585
if (bin_type_id < 0 || bin_type_id >= instance_.bin_types_.size()) {
8686
throw std::invalid_argument(
87-
"packingsolver::box::InstanceBuilder::set_bin_type_maximum_weight: "
87+
FUNC_SIGNATURE + ": "
8888
"invalid 'bin_type_id'; "
8989
"bin_type_id: " + std::to_string(bin_type_id) + "; "
9090
"instance_.bin_types_.size(): " + std::to_string(instance_.bin_types_.size()) + ".");
@@ -172,25 +172,25 @@ ItemTypeId InstanceBuilder::add_item_type(
172172
{
173173
if (x < 0) {
174174
throw std::invalid_argument(
175-
"packingsolver::box::InstanceBuilder::add_item_type: "
175+
FUNC_SIGNATURE + ": "
176176
"item 'x' must be > 0; "
177177
"x: " + std::to_string(x) + ".");
178178
}
179179
if (y < 0) {
180180
throw std::invalid_argument(
181-
"packingsolver::box::InstanceBuilder::add_item_type: "
181+
FUNC_SIGNATURE + ": "
182182
"item 'y' must be > 0; "
183183
"y: " + std::to_string(y) + ".");
184184
}
185185
if (z < 0) {
186186
throw std::invalid_argument(
187-
"packingsolver::box::InstanceBuilder::add_item_type: "
187+
FUNC_SIGNATURE + ": "
188188
"item 'z' must be > 0; "
189189
"z: " + std::to_string(z) + ".");
190190
}
191191
if (copies <= 0) {
192192
throw std::invalid_argument(
193-
"packingsolver::box::InstanceBuilder::add_item_type: "
193+
FUNC_SIGNATURE + ": "
194194
"item 'copies' must be > 0; "
195195
"copies: " + std::to_string(copies) + ".");
196196
}
@@ -212,7 +212,7 @@ void InstanceBuilder::set_item_type_weight(
212212
{
213213
if (item_type_id < 0 || item_type_id >= instance_.item_types_.size()) {
214214
throw std::invalid_argument(
215-
"packingsolver::box::InstanceBuilder::set_item_type_weight: "
215+
FUNC_SIGNATURE + ": "
216216
"invalid 'item_type_id'; "
217217
"item_type_id: " + std::to_string(item_type_id) + "; "
218218
"instance_.item_types_.size(): " + std::to_string(instance_.item_types_.size()) + ".");
@@ -323,7 +323,8 @@ void InstanceBuilder::read_parameters(
323323
std::ifstream f(parameters_path);
324324
if (parameters_path != "" && !f.good()) {
325325
throw std::runtime_error(
326-
"Unable to open file \"" + parameters_path + "\".");
326+
FUNC_SIGNATURE + ": "
327+
"unable to open file \"" + parameters_path + "\".");
327328
}
328329

329330
std::string tmp;
@@ -359,7 +360,8 @@ void InstanceBuilder::read_bin_types(
359360
std::ifstream f(bins_path);
360361
if (!f.good()) {
361362
throw std::runtime_error(
362-
"Unable to open file \"" + bins_path + "\".");
363+
FUNC_SIGNATURE + ": "
364+
"unable to open file \"" + bins_path + "\".");
363365
}
364366

365367
std::string tmp;
@@ -400,15 +402,18 @@ void InstanceBuilder::read_bin_types(
400402

401403
if (x == -1) {
402404
throw std::runtime_error(
403-
"Missing \"X\" column in \"" + bins_path + "\".");
405+
FUNC_SIGNATURE + ": "
406+
"missing \"X\" column in \"" + bins_path + "\".");
404407
}
405408
if (y == -1) {
406409
throw std::runtime_error(
407-
"Missing \"Y\" column in \"" + bins_path + "\".");
410+
FUNC_SIGNATURE + ": "
411+
"missing \"Y\" column in \"" + bins_path + "\".");
408412
}
409413
if (z == -1) {
410414
throw std::runtime_error(
411-
"Missing \"Z\" column in \"" + bins_path + "\".");
415+
FUNC_SIGNATURE + ": "
416+
"missing \"Z\" column in \"" + bins_path + "\".");
412417
}
413418

414419
BinTypeId bin_type_id = add_bin_type(
@@ -430,7 +435,8 @@ void InstanceBuilder::read_item_types(
430435
std::ifstream f(items_path);
431436
if (!f.good()) {
432437
throw std::runtime_error(
433-
"Unable to open file \"" + items_path + "\".");
438+
FUNC_SIGNATURE + ": "
439+
"unable to open file \"" + items_path + "\".");
434440
}
435441

436442
std::string tmp;
@@ -470,15 +476,18 @@ void InstanceBuilder::read_item_types(
470476

471477
if (x == -1) {
472478
throw std::runtime_error(
473-
"Missing \"X\" column in \"" + items_path + "\".");
479+
FUNC_SIGNATURE + ": "
480+
"missing \"X\" column in \"" + items_path + "\".");
474481
}
475482
if (y == -1) {
476483
throw std::runtime_error(
477-
"Missing \"Y\" column in \"" + items_path + "\".");
484+
FUNC_SIGNATURE + ": "
485+
"missing \"Y\" column in \"" + items_path + "\".");
478486
}
479487
if (z == -1) {
480488
throw std::runtime_error(
481-
"Missing \"Z\" column in \"" + items_path + "\".");
489+
FUNC_SIGNATURE + ": "
490+
"missing \"Z\" column in \"" + items_path + "\".");
482491
}
483492

484493
if (profit == -1)
@@ -569,14 +578,14 @@ Instance InstanceBuilder::build()
569578
if (instance_.objective() == Objective::OpenDimensionX
570579
&& instance_.number_of_bins() != 1) {
571580
throw std::invalid_argument(
572-
"packingsolver::box::InstanceBuilder::build: "
581+
FUNC_SIGNATURE + ": "
573582
"the instance has objective OpenDimensionX and contains " + std::to_string(instance_.number_of_bins()) + " bins; "
574583
"an instance with objective OpenDimensionX must contain exactly one bin.");
575584
}
576585
if (instance_.objective() == Objective::OpenDimensionY
577586
&& instance_.number_of_bins() != 1) {
578587
throw std::invalid_argument(
579-
"packingsolver::box::InstanceBuilder::build: "
588+
FUNC_SIGNATURE + ": "
580589
"the instance has objective OpenDimensionY and contains " + std::to_string(instance_.number_of_bins()) + " bins; "
581590
"an instance with objective OpenDimensionY must contain exactly one bin.");
582591
}

src/box/instance_flipper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Point packingsolver::box::convert_point_back(
1616
} else if (direction == Direction::Z) {
1717
return Point{point.z, point.y, point.x};
1818
}
19-
throw std::runtime_error("");
19+
throw std::runtime_error(FUNC_SIGNATURE);
2020
return Point();
2121
}
2222

0 commit comments

Comments
 (0)