O'Reilly logo

Start Here!™ Fundamentals of Microsoft® .NET Programming by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error Handling

No matter how well-designed and implemented a program is, errors will occur eventually. These may be caused by incorrect code or by circumstances outside the program’s control, such as the user entering incorrect values or a printer not being connected to the network.

Different languages handle errors in different ways, but Visual Basic, C#, C++, and Java use a similar approach. The basic syntax in pseudocode is as follows:

Try
    statements...
Catch <exception>
    statements...
Finally
    statements...

The statements after the Try keyword are the ones that might cause an error.

If an error occurs, the program executes the statements after the Catch keyword. (If no error occurs, the program skips those statements.) The variable <exception>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required