Lonnie Best
Lonnie Best

Reputation: 11364

Catching an Unhandled Exception Raised by an Unmanaged Sub-Process

Using C#'s System.Diagnostics.Process object, I start an unmanaged exe, that later starts yet another unmanaged exe.

The 2nd exe is causing an unhandled-exception that I'd like my application to ignore, but can't seem to.

I'm using a try/catch statement when I start the first process, but it doesn't seem to catch the exception raised by the 2nd process. When the exception occurs, the just-in-time debugger notifies me and halts my application until I manually click "yes" I want to debug or "no". Then my application proceeds.

The JIT debugger doesn't have source code for the 2ndprocess.exe that is throwing the exception. So, it doesn't tell me what the exception is. I don't really care what the exception is, I just want to know how to catch it and ignore it so my application doesn't get halted by it. By the time the exception occurs, the work is done anyway.

Can anyone offer some insight?

Upvotes: 1

Views: 1332

Answers (2)

Robert Greiner
Robert Greiner

Reputation: 29722

You should be properly handling the exception in the second executable. Your main program won't catch the exception because it isn't throwing one, it is executing something that is.

Edit:

Do you have access to the source of the second process (the one throwing the exception)? Your application shouldn't ever just crash. If the exceptional case gets handled correctly in the second process, you won't have this problem in your primary application.

Edit2:

Since you have access to the source (open source) I recommend you fix the bug. This will help you in two ways:

1) Your program will finally work.
2) You can say you contributed to an open source project.

And, as a special bonus, you get to help out a project you use frequently. Win/Win

Upvotes: 1

Mitchel Sellers
Mitchel Sellers

Reputation: 63126

Since you are using process.start to actually launch the application, the application creates a separate application domain. Capturing the exception from that application is not something that I believe will be possible, since more than likely the JIT dialog is coming up due to that failed process.

Although not a solution you could stop the dialog if needed, but that has issues of its own.

Upvotes: 1

Related Questions