Making EPERM friendlier, even for C++ programs
Posted Feb 2, 2013 12:43 UTC (Sat) by MrWim
In reply to: Making EPERM friendlier, even for C++ programs
Parent article: Making EPERM friendlier
This is also a frustration of mine. Most exception propagation schemes make only two options easy:
- Allow the exception to propagate (e.g. "cannot convert 'abc' to int") such that the UI can only tell the user exactly that but not more information about the context
- Catch all exceptions and throw another one with context but not (e.g. "Loading simulation failed")
It is far too difficult to provide an error message like "Loading simulation failed because cell B74 of sim.csv contains 'abc' when it should contain a number". It would be nice if it were possible to attach more and more context to an exception as it propagates up the stack. Java has exception.getCause() and C++'s boost::exception has the ability to attach more data to an exception.
I prefer boost's approach but it still sucks as:
- You still need a try...catch block. It would be much nicer to have some sort of RAII style context built up on the stack which would be unrolled.
- To use it all the code you call must throw boost exceptions.
- It is difficult to serialize/deserialize if you want to transport it between threads.
I don't know if other languages have solved this in a nicer way.
to post comments)