Hire Our Expert Programmer & Technical Writer To Do Your Capstone Project
+1 vote
in Programming Languages & Algorithms by

1 Answer

+1 vote
by
selected by (user.guest)
 
Best answer

exception handling can be managed by five keywords.

1. Try: The try block governs the statements that are enclosed within it and defines the scope of exception handler associated with it. Try block follows catch or finally or both. 2. Catch: This is a default exception handler, since the exception class is the base class for all the exception classses, this handler is capable of catching and type of exception.

The catch statement takes an object of exception class as a parameter, if an exception is thrown the statement in the catch block is executed. The catch block is restricted to the statements in the proceeding try block only.

try

{

//statements that may cause exception

}

catch (Exception e)

{

}

3. Finally: When an exception is raised, the statement in the try block is ignored, sometimes it is necessary to process certain statements irrespective of whether an exception is raised or not, the finally block is used for this purpose.

4. Throw: The throw class is used to call exception explicitly. You want to throw an exception when the user enters a wrong login ID and password, you can use the throw statement to do so. The throw statement takes an single argument, which is an object of exception class.

If the object does not belong to a valid exception class, the compiler gives error.

5. Throws: The throws statement specifies the list of exception classes that are thrown by a method. If a method is capable of raising an exception that is does not handled, it must specify the exception that has to be handled the calling method, this is done by using the throw statement.


Related questions

+1 vote
1 answer
+1 vote
1 answer
Welcome to CPENTalk.com

Disclaimer: Every user is solely responsible for anything that he/she posts or uploads on CPENTalk.
...