The new Exception Helper replaces the old Exception Assistant when debugging exceptions in Visual Studio 2017. This new compact helper is fast, moveable, and sizable.
- [Instructor] Visual Studio has always contained diagnostic tools to help the developer understand what's happening when an exception happens during a debugging session. It's important to analyze the situation because it usually means you have a bug in your code or you have an unhandled exception. In Visual Studio 2015, which I have open, here, there are two tools. There is the exception assistant and the exception dialogue. When you're in managed code, you typically get the exception assistant, and when you're in unmanaged code, you get the exception dialogue.
Here's what I mean. I'm running this WPF application inside Visual Studio. I've got the debugger attached. I'll click on this first button. When I hit my exception, I see the exception on line 36, and I get this dialogue that pops up and shows me information about the exception. Now, this is a useful bit of information, but there are some problems with it. Number one, it's a very large dialogue, and it's not re-sizeable. So if I want to see the code that's behind it, I can do one of two things. I can drag it around, and then I get a transparent, semi-transparent see-through dialogue, or I can close this.
Then if I want to see the error information again, I'll go back over here and click on this open exception. So that's what it looks like when you're in a managed application. If you're in an unmanaged application, you get a dialogue, which looks like this. I'll go to tools, options. I'll go to debugging, and then general. And then I'll turn off the exception assistant. Now I'll get the same dialogue that you would get if you were were working with unmanaged code.
Looks like this. And the issue with this is you can't switch back to your code. You have to close this dialogue, basically do a break or continue, and it's harder to see what's going on in the code. So Microsoft has fixed both of these in 2017. Let's take a look. This is the same project open in Visual Studio 2017. This time, when I hit the exception while debugging the application, I see the exception helper.
It's a lot smaller than the exception assistant. In fact, it might be a little bit too small, but that's not a problem because it's sizeable. So I can make it whatever size I need to read the details. It's still obscuring my text. I can move up and down, and you'll see that the exception helper is pinned to this location. So if I don't want that, if I want to be able to see this text that's obscured, I can unpin the exception helper, and then move it where I need it. I can move it down here out of the way. Now I can scroll up and down and read my code while my exception details are still here where I can see them.
A nice feature about this is it remembers the location the next time you have a debug session. I'll show you what I mean. I'll stop debugging, restart. And you'll see that the exception helper's in the previous location. I'll re-pin it, which puts it back in the default location, so now it moves with the code. There's some other features we should look at, which is I can close this and then bring it back by clicking on the red x. And then there'll be times when you'll need to see extra information about your exception.
One of the things Microsoft did here is they made it a small, compact bit of information. It's just information about the argument out of range exception. There'll be times when you'll want to know more about it, so to do that, you'll go to view details. This opens the quick watch window. It's using an expression called pound exception to retrieve the exception information, and I can click here to get the details. Read whatever information I need here and then close that. Go back to the code, and we've got the small exception helper here.
You can also copy those details to your clipboard, and you can go to your exception settings by opening this portion of the helper. Now you can do things like force Visual Studio to break when this exception type is thrown. This was useful when you have a catch block that's catching this argument out of range exception, but you still want to have the code halted when that exception occurs. You can also open the exception settings. I get the exception settings down here.
And you can edit conditions. One additional benefit of the exception helper is that it also works in unmanaged code, so you'll no longer see the exception dialogue. Let me show you one other feature. I'll stop the application and start it again. Click on the second button this time. What I'm doing here is, I've got some code here that at this point is dividing by zero, and so I'm catching that divide by zero exception, and then I'm throwing my own exception argument out of range exception to say that this argument's out of range.
So what I want you to see is that the exception helper shows you the main exception, but it also shows you the details about the inner exception. So they're both visible there. So no longer do you have to drill down into the details just to find the information. You don't have to go here, here, here to find that information. It's visible right in the helper.
- Installing Visual Studio 2017
- Using debugging features
- Reviewing document navigation enhancements
- Examining IntelliSense Improvements
- Using XAML tools
- Reviewing the tooling added to support Docker containers
- Debugging without the hosting process
- Using the Visual Studio 2017 Installer