J
Jon Davis
In order to gracefully handle exceptions at runtime but cause the debugger to break in the place where the exceptions occur when debugging, I used to write code like this:
#if !DEBUG
try {
#endif
...
#if !DEBUG
} catch {
#endif
...
#if !DEBUG
}
#endif
Now I'm working for a company where all the code that gets pushed is in DEBUG mode rather than RELEASE. I can't rock the boat enough to change this practice. So now I use this ...
try {
...
} catch {
if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
...
}
Half the time I am able to move the runtime line of code back into somewhere in the try block or above it, but half the time it just says it can't move off the current line (with seemingly no rhyme or reason). This solution involves a lot more typing than before, as well.
So my question is, is there some way I can simulate the old way of using #if DEBUG, but set the flag at runtime so that the "try {" / "} catch {..}" is not executed as such and I can get the debugger to break exactly where I want it, but be handled gracefully when the debugger isn't attached?
Thanks,
Jon
#if !DEBUG
try {
#endif
...
#if !DEBUG
} catch {
#endif
...
#if !DEBUG
}
#endif
Now I'm working for a company where all the code that gets pushed is in DEBUG mode rather than RELEASE. I can't rock the boat enough to change this practice. So now I use this ...
try {
...
} catch {
if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
...
}
Half the time I am able to move the runtime line of code back into somewhere in the try block or above it, but half the time it just says it can't move off the current line (with seemingly no rhyme or reason). This solution involves a lot more typing than before, as well.
So my question is, is there some way I can simulate the old way of using #if DEBUG, but set the flag at runtime so that the "try {" / "} catch {..}" is not executed as such and I can get the debugger to break exactly where I want it, but be handled gracefully when the debugger isn't attached?
Thanks,
Jon