One: Improvement error handling

Created on 30 Jun 2020  路  4Comments  路  Source: Samsung/ONE

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.

  1. change assert() to throw std::runtime_error("")
  2. make exception.h and describe several exception types.

If have a good idea, please comment.

areonert future

Most helpful comment

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 { ... };

All 4 comments

What I used;

  • use 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.
  • use 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 { ... };

2813

uploaded Draft PR. Please review.

FYI @KimDongEon is tied with other work so he won't continue this work. I put future label.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

underflow101 picture underflow101  路  4Comments

lucenticus picture lucenticus  路  3Comments

periannath picture periannath  路  3Comments

ragmani picture ragmani  路  4Comments

kishcs picture kishcs  路  3Comments