Here’s a scenario just about everyone has run into: you had this try/catch block:
try { // ... } catch (Exception) { // ... }
You didn’t need the exception variable, for whatever reason. Although you’d typically leave it there in case you needed to dig deeper into the exception, you got tired of Visual Studio nagging about the unused variable, and removed it.
And then, it happened: an exception occurred, and you actually needed the detail.
As it turns out, there’s a way you can see the exception detail without adding the exception variable back and reproducing the issue a second time. There’s a special $exception
variable that you can use in the Locals, Watches, or Immediate windows:
An additional benefit is that since $exception
is local to the scope in which your instruction pointer is, you can check the exception detail even if you’re looking at code elsewhere in the project, without having to go back and find the exact place where your exception was thrown.
A big thanks goes to this Stack Overflow answer for this handy little tip.