OO Exception- CX_STATIC_CHECK Multiple Catch & Clean Up


 

MULTIPLE CATCH in single [TRY .. ENDTRY] block

Step1. So here we have the program with two exception classes. based on some condition two different exceptions are raised in the VALIDATE_INPUT method. The exception is handled in  where the VALIDATE_INPUT method is called with Multiple CATCH statement in the TRY ENDTRY block. Run the program with different sets of inputs.

Step2. Input number as 50.

Step3. No exception is raised and we have the output.

Step4. Run with 0 .

Step5. We have the first exception handled and the Code after the particular CATCH statement is executed.

Step6. So here we have another input number. Execute it.

Step7. Here the Second exception handled and the Code after the particular CATCH statement is executed.

CLEANUP- The context of the TRY & ENDTRY block can be cleaned up in the CLEANUP block. As exception leads to end the program prematurely, cleanup block can be used to release external resources which an external resources no longer has access.

Step8. Here is the program When the exception is raised then the code under the CLEANUP block is executed. Execute the program.

Step9. Here when the exception is raised then the cleanup block is executed. Here we are clearing some variables or we can free the memory and then the exception is catched.

Step10. So here we have the output.

 

 


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s