Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Normally I use something like this to try and catch all unexpected top-level exceptions.</p> <pre><code>using System; static class Program { [STAThread] static void Main(string[] argv) { try { AppDomain.CurrentDomain.UnhandledException += (sender,e) =&gt; FatalExceptionObject(e.ExceptionObject); Application.ThreadException += (sender,e) =&gt; FatalExceptionHandler.Handle(e.Exception); // whatever you need/want here Application.Run(new MainWindow()); } catch (Exception huh) { FatalExceptionHandler.Handle(huh); } } static void FatalExceptionObject(object exceptionObject) { var huh = exceptionObject as Exception; if (huh == null) { huh = new NotSupportedException( "Unhandled exception doesn't derive from System.Exception: " + exceptionObject.ToString() ); } FatalExceptionHandler.Handle(huh); } } </code></pre> <p>Maybe it is something you find helpful too? This main code routes all three ways of catching unexpected top-level exceptions through one method call. All you now need is a static class <code>FatalExceptionHandler</code> that includes your top-level exception handling in its <code>Handle</code> method.</p> <p>And really, any application developer knows there are really just two things to do there:</p> <ol> <li>Show/log the exception like you see fit</li> <li>Make sure you exit/kill the application process</li> </ol> <p>If you think item two is strange, remember that we only bother to do this in the first place for really exceptional situations. These things are probably bugs that need changes to your application to be accurately addressed. Any other exception handling - the functional kind - should be lower down inside your actual program code, catching specific kinds of exceptions where this makes sense and handling them there in the way that makes sense. Anything else should bubble up to your <code>FatalExceptionHandler</code> to make itself known and stop the possibly crippled program from working from corrupted state</p> <p>Dead programs tell no lies... ;-)</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