|
|
|
|
|
by Suncho
4480 days ago
|
|
Out of curiosity, how would you recommend handling a situation in which a file close fails? My instinct is to have an RAII class whose destructor catches any exceptions, adds the error to some list somewhere, and doesn't rethrow anything. What's an example of a language you like that does exceptions in a better way? |
|
ret, e = _some_function() # e is non-null if an exception/error happened
ret = some_function() # on error, an exception is raised and caught by the first parent function that used _call() syntax (leading underscore)
So basically, _func() means call func(), and have an extra return value that is an exception or Null if no error. All one has to implement is either a _func or func, not both, the compiler handles the conversion.
So bottom line, you can write real exception safe code and not have to worry about a panic/exception breaking the flow, by using _func() calls, or you can bail by using func() calls, it's your choice.
edit: not sure how this ties in to RAII, if at all. Guess I should get back to the drawing board... :-)