Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>FIRST OF ALL:</strong></p> <p>You don't want to do that. </p> <p>Exceptions are not meant for handling <em>bugs</em>, but run-time error conditions that make it impossible for your function to satisfy the pre-conditions of other functions it has to call, or to keep the promise of fulfilling its own post-conditions (given that the caller has satisfied the pre-conditions). See, for instance, <a href="http://www.drdobbs.com/when-and-how-to-use-exceptions/184401836" rel="nofollow">this article by Herb Sutter</a>.</p> <p>Don't ever write anything like this:</p> <pre><code>try { //bug condition &lt;== NO! Exceptions are not meant to handle bugs } catch() { //Remove file } </code></pre> <p>But rather:</p> <pre><code>assert( /* bug condition... */ ); </code></pre> <p><strong>BACK TO THE QUESTION:</strong></p> <p>Your program has undefined behavior, and most likely it will not throw any exception at all when you do:</p> <pre><code>char TempArray[10]; char c = TempArray[11]; </code></pre> <p>So catching all exceptions won't help. This is a bug, i.e. a <em>programming</em> error, and it is arguable whether you should handle bugs in a way that transfer controls to a buggy routine; moreover, if you are admitting the presence of bugs in your program, couldn't you just be transferring control to a buggy handler? That may make it even worse.</p> <p>Bugs should be dealt with by <em>preventing</em> them, making use of assertions, perhaps adopting methodologies such as test-driven development, and so on.</p> <p>This said, regarding a way to catch all exceptions, you can do:</p> <pre><code>try { // ... } catch (...) // &lt;== THIS WILL CATCH ANY EXCEPTION { } </code></pre> <p>But using <code>catch (...)</code> is discouraged as a design guideline, because it easily leads to swallow error conditions that are meant to be handled and forget about them. After all, exceptions were invented exactly to prevent programmers to forget checking error codes, and <code>catch (...)</code> makes that so easy.</p> <p>For a catch-everything purpose, it would be better to let all of your exceptions derive from <code>std::exception</code>, and then do:</p> <pre><code>try { // ... } catch (std::exception&amp; e) { // Do something with e... } </code></pre>
    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.
 

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