views:

274

answers:

2

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?

+1  A: 

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.

Mitchel Sellers
Are you suggesting that stopping the dialog would also lead to my application not halting at the time the dialog would normally appear?
LonnieBest
+1  A: 

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

Robert Greiner
My application isn't explicitly launching the 2nd process. The first process (which is unmanaged) is launching it. So how can I "properly handle" the 2nd process?
LonnieBest
Unless 2ndprocess.exe is an external component over which they have no control...We've seen this before.
Byron Ross
@Byron that could be the case, if you can't fix it, then I guess it's best to have the primary application create the conditions necessary not to get that exception, if that's even possible in this situation.
Robert Greiner
@Robert, I'm not even sure my application is (as you say) "getting" the exception. Because, my application doesn't crash, it just halts until I manually acknowledge "yes" or "no" to the JIT debugger dialog that pops up.
LonnieBest
Right, your application isn't catching the exception, that's the problem. Your second app (executed by the first) is throwing the exception within its program space. Your main application will never know about the thrown exception.
Robert Greiner
Yeah, it never knows about it, but it does halt it. You, see when the 2nd process fails like this, my first process fails also (which I can catch and handle). I guess there's no easy way to prevent this halt, because the thing halting my app, is outside my app's ability to monoitor and control it. I wish there was some way to fore-warn my app to watch for that exception occurring outside its natural scope, and dismiss it programmatically.
LonnieBest
So, I'm assuming you don't have access to the source code for the 2nd process?
Robert Greiner
see edits, I recommend you fix the code which will fix your application and give you some fame.
Robert Greiner