Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not throwing exceptions in your own code is relatively easy: you just don't use the <code>throw</code> statement.</p> <p>Not throwing exceptions from memory allocation failures is a little more painful: either you don't use normal <code>new</code> (use <code>new(std::nothrow)</code> or <code>malloc</code> or something instead), or you use some nonstandard compiler option to get it to do something nonstandard when it fails (e.g. immediately terminate your program, or return <code>0</code>), or you override <code>operator new</code> to do something nonstandard when it fails.</p> <p>If your chosen approach is to immediately terminate the program, you can implement this with <code>set_new_handler()</code>, which I had forgotten about until litb reminded me.</p> <p>That leaves the problem of dealing with exceptions generated by C++ libraries you don't maintain. Generally you'll have to wrap library calls in a wrapper that looks something like this:</p> <pre><code>int DoSomething(int &amp;output, const int input) throw() { try { output = library_do_something(input); return 1; } catch (...) { return 0; } } </code></pre> <p>The <code>catch (...)</code> catches all possible C++ exceptions from <code>library_do_something</code> (as well as the assignment operator on <code>output</code>, which isn't relevant here), throws away all the information they may have contained, and then maps all those failures to <code>0</code>.</p> <p>Note that this style means that you can't use RAII at all, not even a little bit, because you have no way of signaling failure within a constructor. The whole point of RAII is that you acquire all your resources inside of constructors so that they will be properly released by a destructor during exception propagation. But resource acquisition is something that can essentially always fail. So you can't do that inside a constructor.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload