title: Portably handle exceptional errors in C++
body: <p>I'm working on porting a Visual C++ application to GCC (should build on MingW and Linux).</p>
  
  <p>The existing code uses <code>__try { ... } __except(1) { ... }</code> blocks in a few places so that almost nothing (short of maybe out of memory type errors?) would make the program exit without doing some minimal logging.</p>
  
  <p>What are the options for doing something similar with GCC?</p>
  
  <p>Edit: Thanks for the pointer to /EH options in Visual Studio, what I need now is some examples on how to handle signals on Linux. I've found <a href="http://gcc.gnu.org/ml/gcc-help/2002-04/msg00003.html" rel="nofollow noreferrer">this message</a> from 2002.</p>
  
  <p>What other signals besides <code>SIGFPE</code> and <code>SIGSEVG</code> should I watch out for? (Mostly care about ones that might be raised from <em>me</em> doing something wrong)</p>
  
  <p><strong>Bounty Information</strong>:
  I want my application to be able to self-log as many error conditions as possible before it exits. </p>
  
  <p>What signals might I get and which would generally be impossible to log an error message after? (Out of memory, what else?)</p>
  
  <p>How can I handle exceptions and (most importantly) signals in a portable way that the code at least works the same on Linux and MingW. #ifdef is OK.</p>
  
  <p>The reason I don't just have a wrapper process that logs the failure is that for performance reasons I save writing some data to disk till the last minute, so if something goes wrong I want to make all possible attempts to write the data out before exiting.</p>