Exception Handlers:- Java Provides us Various Exception Handlers For Handling Exceptions The Various types of Exception Handlers are :
1) Try:- Code which we have doubt that it could creates an Exception is placed in the try block The Try Block Contains that Code Which contains Any Invalid Operations or the Code that may Generates an Error
2) Catch Block :- Every Try Block Must have an at least one try Block When An Exception has occurred in the Try Block then the Error Code is just Passed to the Catch Block Which Will handle the Particular Exception and Gives Appropriate Message to the
A Try Block May have Multiple Catch Blocks But One Try Block May Contains At Least One Catch Block Because in the user Code There is the Possibility of occurring of two or More Errors and A User Code can contains code which have Multiple Operations Like A User Contains the Code Which Contains Division of Array Elements Then it is Possible of Occurring Array Index Out of Bound Exception and Either it may Generate Arithmetic Exception So There is the Possibility of Occurrence of Multiple Catch Blocks of one try Block
3) Finally Block:- This is the third most popular Exception handler which is used for Performing the Code that may Cause Exceptions or Not .Means Finally Block Must be Executed Either the Exception May Occurred or Not or The Code that Contains important Code that must be Executed in any Situation Either an Exception Occurred or Not it Executed its Code it Contains Code Like De-allocation of Memory ,Closing Files etc.
Throws Exception: - We know that For Handling an Exception a user has to use Try and Catch Block But There is the Built in Exception Handler which provides us the Capability For Not Handling Exception by using try and catch Block In This When an Exception has occurred then the Compiler Will Handle this Exception The Code Will throws an Exception For Compiler and this Exception Will be Handle by the user
Throw :- Java ‘s Exception Handlers provides the Facility for the User to creating his own Exceptions if a user wants to Create his Own Exception then ha may use throw Keyword For creating his own Error and with Respective Error Message
Dinesh Thakur is a Columinist and designer with strong passion and founder
of Computer Notes. if you have any ideas or any request please get @me on Google+
![]()