How do I get at the exception information when using MiniDumpWriteDump out-of-process?

You also need the MINIDUMP_EXCEPTION_INFORMATION.ThreadId value. The simplest way, and the way I made it work, is to use a memory-mapped file to transfer both the ThreadId and the ExceptionPointers. And a named event to wake up the watchdog. It doesn’t matter that the pointer is not valid in the context of the watchdog process. … Read more

catch another process unhandled exception

You can try something like that to avoid the debugger question to appear, you won’t get the exception but only the exit code: class Program { static void Main(string[] args) { try { ProcessStartInfo info = new ProcessStartInfo(“ErroneusApp.exe”); info.ErrorDialog = false; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.CreateNoWindow = true; info.UseShellExecute = false; System.Diagnostics.Process p … Read more

How can I set up .NET UnhandledException handling in a Windows service?

The reason that the UnhandledException event on the current AppDomain does not fire is how services are executed. User sends a Start command from the Windows Service Control Manager (SCM). The command is received by the framework’s ServiceBase implementation and dispatched to the OnStart method. The OnStart method is called. Any exception which is thrown … Read more

Why is “throws Exception” necessary when calling a function?

In Java, as you may know, exceptions can be categorized into two: One that needs the throws clause or must be handled if you don’t specify one and another one that doesn’t. Now, see the following figure: In Java, you can throw anything that extends the Throwable class. However, you don’t need to specify a … Read more

Unhandled exceptions in BackgroundWorker

What you’re describing is not the defined behavior of BackgroundWorker. You’re doing something wrong, I suspect. Here’s a little sample that proves BackgroundWorker eats exceptions in DoWork, and makes them available to you in RunWorkerCompleted: var worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { throw new InvalidOperationException(“oh shiznit!”); }; worker.RunWorkerCompleted += (sender, e) … Read more

catch all unhandled exceptions in ASP.NET Web Api

This is now possible with WebAPI 2.1 (see the What’s New): Create one or more implementations of IExceptionLogger. For example: public class TraceExceptionLogger : ExceptionLogger { public override void Log(ExceptionLoggerContext context) { Trace.TraceError(context.ExceptionContext.Exception.ToString()); } } Then register with your application’s HttpConfiguration, inside a config callback like so: config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); or directly: GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger());