Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Considering how hard it is to write truly exception-safe C++

Is "writing truly exception-safe" something that necessary ? for me, the biggest benefit of exceptions is that I can have some code throw from anywhere and display a nice error pop-up message to my user which informs me of what went wrong and revert what was currently happening during the processing of the current event, since the "top-level" event loop is wrapped in a try-catch block. Often enough, the user can then just resume doing whatever he was working on.



> Is "writing truly exception-safe" something that necessary?

If you want your connections cleanly terminated, your temporary files removed, and your database transactions invalidated, yes.


> If you want your connections cleanly terminated, your temporary files removed, and your database transactions invalidated, yes.

sure, and if you develop in C++ and put these in RAII classes they will be automatically.


Because they're exception safe. But it's also possible to use them in an exception unsafe way.


well, that's what I don't understand with OP's

> Considering how hard it is to write truly exception-safe C++

that's the default behaviour in C++ code, how hard can it be ?


Exception safety is hardly a "default behavior" of C++, considering such gems[1] as:

    // This is unsafe.
    sink( unique_ptr<widget>{new widget{}},
          unique_ptr<gadget>{new gadget{}} );

    // This is safe.
    sink( make_unique<widget>(), make_unique<gadget>() );
[1] https://herbsutter.com/2013/05/29/gotw-89-solution-smart-poi...


The default nowadays is basic exception safety, where nothing leaks but objects can get put in invalid states. Strong exception safety (rollback semantics) is still pretty hard.


I'm pretty sure that's what is meant by "truly exception-safe".


If your code isn't exception-safe, then carrying on after an exception may crash the program.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: