Language: Try-Catch-Finally

This solution demonstrates the new Try, Catch, Finally error handling in Visual Basic .NET. Press F5 to start the application in Debug mode using the breakpoints. Press Ctrl+F5 to run the program and ignore the breakpoints.

Featured Highlights

There are 5 command buttons to test. Each one tries to open the file specified in the text box labeled 'Text File To Open.' Each button (except the one labeled 'No Error Handling') uses various degrees of error handling using Try, Catch, and Finally blocks.

Requirements

Requires the Trial or Release version of Visual Studio .NET Professional (or greater).

Running the Sample

When you run the example from within Visual Studio .NET, the debugger will be invoked via breakpoints for each button. You can selectively turn the breakpoints on and off by using the Breakpoints Window, accessible via the Debug | Windows | Breakpoints menu command or the CTRL+ALT+B keystroke.

In the code samples, the new .NET Framework version of MsgBox (MessageBox from the System.Windows.Forms namespace) is used. In Visual Basic .NET applications, MsgBox will continue to work fine. However, C# and other languages do not expose MsgBox. Use MessageBox instead in those cases.

Last Update: 7 July 2002