views:

211

answers:

5

I'm using VS2008 to debug an application that starts a new process. I believe that the spawned process is suffering (and handling) some kind of CLR exception during its start-up, but it is not being caught by turning on CLR Exception Notification in Debug -> Exceptions. Any suggestions on how I can see where the exception is generated? I would normally just attach to the newly spawned process, but since the exception is occurring at start-up, there isn't enough time to do it.

A: 

If the process fails during startup, then CreateProcess should return an error code. Check the error code.

If the process fails directly after startup, then check the process return code, and its documentation, logs etc.

A: 

Well you could log the error. But that doesn't allow you to look at it. To do that you might consider putting a serious delay (or infinte loop) in the exception handler. That will give you all the time you need to attach to the process and debug it. Just make sure that you remove it beofre you go into production!!

Craig
+4  A: 

You can add a call to Debugger.Launch() in your process startup code. This will launch a debugger (typically giving you the choice of using the running copy of VS2008 or a new copy) attached to the process. The same trick is handy for debugging Service startup issues.

Harper Shelby
Sweet. I'll give that a try.
PeterAllenWebb
Nice one. Consider that upvoted!!
Craig
A: 

If you have control over this process code, use Debugger.Launch().

If not, try:

Just start this process from the command line and see the output. If there is unhanded exception, it'll be shown.

If it does not show anything, use the command line debugger, and use the command ca[tch].

Sunny
+1  A: 

Another trick that's worth considering is to use "Image File Execution Options", take a look at this post on blogs.msdn.com: http://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx as this doesn't require any changes to be made to the child executable or parent executable.

Rob