Microsoft Visual Basic 2013 Step by Step

Microsoft Visual Basic 2013 Step by Step

Author:Michael Halvorson [Michael Halvorson]
Language: eng
Format: epub
Tags: COMPUTERS / Programming Languages / Visual BASIC
ISBN: 9780735673403
Publisher: Microsoft Press
Published: 2013-11-18T16:00:00+00:00


Setting the trap: the Try…Catch code block

To create an exception handler in code, you place the Try statement in a routine right before the statement you’re worried about, and the Catch statement follows immediately with a list of the statements that you want to run if an exception actually occurs. A number of optional statements, such as Finally, Exit Try, and nested Try…Catch code blocks can also be included, as the examples in this chapter will demonstrate. The typical components of a Try…Catch exception handler are as follows:

Try Statements that might produce a run-time error Catch Statements to run if a run-time error occurs Finally Optional statements to run whether an error occurs or not End Try

The Try statement identifies the beginning of an error handler in which Try, Catch, and End Try are the essential keywords, and Finally and the statements that follow are optional. Note that programmers sometimes call the statements between the Try and Catch keywords protected code because any run-time errors resulting from these statements won’t cause the program to crash. (Instead, Visual Basic executes the error-handling statements in the Catch code block.)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.