C #: When you can debug the catch, can you get an implicit declaration?

This is a compiler warning and is generally not approved for using unused variables in your code. So the following will raise a warning because e is not used

try {
  throw new InvalidOpreationException();
}
catch(Exception e) {
}

      

The correct way to do this is to not give the exception a name unless you intend to use it:

try {
  throw new InvalidOpreationException();
}
catch(Exception) {
}

      

But this "right" way of doing things can be a problem when debugging. You can set a breakpoint inside the catch, but you won't know why you came there, unless you stop the application, throw an exception, recompile, and re-create the error. This is very frustrating, to say the least.

The kicker is that this exception still exists, it just doesn't have an explicit name in this area. Is there a way to access it anyway?

+2


source to share


2 answers


Try adding $ exception to the viewport. This will be due to an active exception on the current thread. You can parse this variable to find out the runtime type and any details you need.

I have checked this with Visual Studio 2008 onwards.

EDIT



This type of function is known as pseudovariant in the visual studio debugger. You can get the complete list (broken down by language) in the following place.

+16


source


the compiler warning exists because you are declaring the witch variable is not used. If you have to, do something about it and the warming will go away (log the error in the txt file, for example)



0


source







All Articles