I am trying to improve error handling.
It is difficult to distinguish whether the current error is a user error or a system error.
There are two options.
Any comments would be appreciated.
If have a good idea, please comment.
What I used;
assert when we expect the values for functions to work as minimum condition. usually for internal functions. this is not related with user interface. false case should not exist for normal cases. it's an alert for developers for debugging.throw for inputs that can exist but want to stop the program as it's an error. may start from user input.Agree with @seanshpark, assert is to check developers'(our) faults and throw is for invalid user inputs(and other runtime errors). I agree with changing wrongly called asserts to throws but basically I would prefer to keeping this principle.
Apart from that, for runtime errors from making many types of Exception is welcome. I always wanted to do that someday. Currently we throw std::runtime_error from almost all places, which is temporary.
Something like...
class OnertException : public std::exception { ... }; // Our base exception
class ExecutionFailedException: public OnertException { ... };
class FileNotFoundException: public OnertException { ... };
uploaded Draft PR. Please review.
FYI @KimDongEon is tied with other work so he won't continue this work. I put future label.
Most helpful comment
Agree with @seanshpark,
assertis to check developers'(our) faults andthrowis for invalid user inputs(and other runtime errors). I agree with changing wrongly calledasserts tothrows but basically I would prefer to keeping this principle.Apart from that, for runtime errors from making many types of
Exceptionis welcome. I always wanted to do that someday. Currently we throwstd::runtime_errorfrom almost all places, which is temporary.Something like...