Catch {…..}

The Catch block is the part in the script which handles the errors generated by the Try block. We can define which type of error to be handled by the Catch block. A type of error is an exception of a Microsoft .NET framework. A Try block can have multiple catch blocks for different types of errors. Instead of the Catch block, you can also use the Trap block for handling the errors.

Syntax of Catch block

The following box shows the syntax of the catch block:

catch [ [<error type>] [',' <error type>] *]   

{  

          Statement-1  

          Statement-2  

          Statement-N  

} 

The types of errors appear in the brackets. The outermost bracket shows that the element is optional. In the above syntax, the catch keyword is followed by an optional list of error type specifications and a list of statements. When anyone catch block is found, then the statements in the catch block are executed.

Finally {……}

The ‘finally’ block is a part of a script which is used to free a resource that no longer needed by a script.

The following box shows the syntax of the Finally block:

finally  

{  

          Statement-1  

          Statement-2  

          Statement-N  

}         

The ‘finally’ block is followed by single or multiple statements which are enclosed in the braces that execute every time when the script is executed.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *