title: .NET Global exception handler in console application
body: <p>Question: I want to define a global exception handler for unhandled exceptions in my console application. In asp.net, one can define one in global.asax, and in windows applications /services, one can define as below</p>
  
  <pre><code>AppDomain currentDomain = AppDomain.CurrentDomain;
  currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);
  </code></pre>
  
  <p>But how can I define a global exception handler for a console application ?<br />
  currentDomain seems not to work (.NET 2.0) ?</p>
  
  <p><strong>Edit:</strong><br /></p>
  
  <p>Argh, stupid mistake.<br />
  In VB.NET, one needs to add the "AddHandler" keyword in front of currentDomain, or else one doesn't see the UnhandledException event in IntelliSense... <br />
  That's because the VB.NET and C# compilers treat event handling differently.</p>