Home > Linux > C++ exception-handling tricks for LinuxC++ exception-handling tricks for Linux Eugenia Loli 2005-02-24 Linux 7 CommentsHandling exceptions in C++ has a few implicit restrictions at the language level, but you can get around them in some instances. Learn ways to make exceptions work for you so you can produce more reliable applications. About The Author Eugenia LoliEx-programmer, ex-editor in chief at OSNews.com, now a visual artist/filmmaker.Follow me on Twitter @EugeniaLoli 7 Comments 2005-02-24 9:59 pm One warning about using exceptions from signal handlers: it only works for syncronous signals like FPE, ILL or SEGV. Async signals like INT, TERM or ALRM will not work because the stack frame isn’t guaranteed to be right. There are system-specific ways to make it work if you really need it, there’s some code that does it in GCJ. 2005-02-24 11:25 pm Exceptions in C++ are powers of the dark side. They are easy and strong, but horrible unreliable and unusable for anything cross-platforms.And besides they slow down everything to a crawl. Once there was a 10% gain by giving g++ -fno-exceptions. Today it is only a penalty for the fools who use them. 2005-02-24 11:46 pm When used correctly, they can do a lot of good for making things both easier to read, less source code to deal with, and make things more reliable. However, they shouldn’t be used except in “exceptional” cases involving resource problems or real flaws. ANTLR is an example of a library that uses them for normal flow control, which seems sick and wrong to me. 2005-02-25 3:11 am If you hate exceptions, what made you read an article titled C++ exception-handling tricks for Linux?I love exceptions, in C++, Java, Python and Perl (eval/die in Perl). I guess we’d better never work together in software design. 2005-02-25 4:31 am If you both have valid reasoning, it’s a good reason why you should work together. Maybe in the end you’ll both be better off.. 2005-02-25 2:49 pm If you love exceptions try out uC++. You cannot beat the exception handling capabilities here:http://plg.uwaterloo.ca/~usystem/uC++.htmlAnd don’t forget concurrent programming and exception handling . It’s all right there! 2005-02-25 3:10 pm And besides they slow down everything to a crawl. Once there was a 10% gain by giving g++ -fno-exceptions. Today it is only a penalty for the fools who use them.I thought that only with the MS C++ compilers you pay a performance penalty for using exceptions even when not throwing them. Otherwise, non-thrown exceptions are supposed to be “free”.