0 Bewertungen0% fanden dieses Dokument nützlich (0 Abstimmungen)
25 Ansichten4 Seiten
Exception handling is the process of responding to the occurrence, during computation, of exceptions requiring special processing. It is provided by specialized programming language constructs or computer hardware mechanisms. Software Exception handling mechanisms in modern / day languages are typically non / resumable (0termination semantics0.xceptions are chec!ed at compile / time 7 it should be handle with try / catch bloc! or throws!eyword.
Exception handling is the process of responding to the occurrence, during computation, of exceptions requiring special processing. It is provided by specialized programming language constructs or computer hardware mechanisms. Software Exception handling mechanisms in modern / day languages are typically non / resumable (0termination semantics0.xceptions are chec!ed at compile / time 7 it should be handle with try / catch bloc! or throws!eyword.
Exception handling is the process of responding to the occurrence, during computation, of exceptions requiring special processing. It is provided by specialized programming language constructs or computer hardware mechanisms. Software Exception handling mechanisms in modern / day languages are typically non / resumable (0termination semantics0.xceptions are chec!ed at compile / time 7 it should be handle with try / catch bloc! or throws!eyword.
Exception handling is the process of responding to the occurrence, during computation,
of exceptions anomalous or exceptional events requiring special processing often
changing the normal flow of program execution. It is provided by specialized programming language constructs or computer hardware mechanisms. An exception is handled (resolved by saving the current state of execution in a predefined place and switching the execution to a specific subroutine !nown as an exception handler. Hardware Exception - "ardware exception mechanisms are processed by the #$%. It is intended to support error detection and redirects the program flow to error handling service routines. &he state before the exception is saved on the stac!. Software Exception 'oftware exception handling developed in (isp in the )*+,s and )*-,s. .xception handling mechanisms in modern/day languages are typically non/resumable (0termination semantics0 as opposed to hardware exceptions, which are typically resumable. 1b2ective 1utcome NullPointerException ArrayIndexOutOfBoundsException ArithmeticException IllegalArgumentException Unchecked ArrayIndex1ut1f3ounds.xception #lass#ast.xception IllegalArgument.xception Illegal'tate.xception 4ull$ointer.xception 4umber5ormat.xception Assertion.rror .xceptionInInitializer.rror 'tac!1verflow.rror 4o#lass6ef5ound.rror '.4o #hec!ed .xceptions %nchec!ed .xceptions ) .xceptions are chec!ed at compile/ time .xceptions are not chec!ed at compile time 7 it should be handle with try/catch bloc! or throws !eyword It may or may not be handled 8 If not handled give the compilation error. It doesn9t give the compilation error. : .xception I1.xception 5ile4ot5ound.xception ArrayIndex1ut1f3ounds.xception #lass#ast.xception IllegalArgument.xception $arse.xception #lass4ot5ound.xception #lone4ot'upported.xception Instantiation.xception Interrupted.xception 4o'uch;ethod.xception 4o'uch5ield.xception Illegal'tate.xception 4ull$ointer.xception 4umber5ormat.xception Assertion.rror .xceptionInInitializer.rror 'tac!1verflow.rror 4o#lass6ef5ound.rror < &he #hec!ed exception class is .xception The unchecked exceptions classes are the class RuntimeException and its subclasses, and the class Error and its subclasses. '.4o #hec!ed .xceptions %nchec!ed .xceptions ) .xceptions are chec!ed at compile/ time .xceptions are not chec!ed at compile time 7 it should be handle with try/catch bloc! or throws !eyword It may or may not be handled 8 If not handled give the compilation error. It doesn9t give the compilation error. : .xception I1.xception 5ile4ot5ound.xception ArrayIndex1ut1f3ounds.xception 4umber5ormat.xception 4o#lass6ef5ound.rror < &he chec!ed exception classes are .xception and its subclasses except =untime.xception &he unchecked exceptions classes are the class =untime.xception and its subclasses. '.4o &hrow throws ) .xception thrown by the 7 8 : < Java Exception Handling 1. Exception Handling 2. try & catch block and Handling Exceptions . !ultiple catch block Handling ". #ested try catch block Handling $. %inally block in Java &. thro' key'ord in (ava ). thro's key'ord in Java *. Exception propagation in Java +. Handle exceptions in overriding ,ethods in Java 1-. User de%ined Exception in Java 11. !ultiple Exceptions .n Java ) #e' /oncept 12. 0i%%erent Exception 1enerate in 2rray in Java3)4 5hat are Java Exceptions6 A >ava .xception is an abnormal condition that arises during the execution of a program and also called a run/time error. An exception in >ava signals the unusual or catastrophic situations that can arise. .xamples of >ava .xceptions are? Incorrect user input such as division by zero 5ile that needs to be opened not found 4etwor! connection problem /o,,on scenarios o% Exception Handling 'here exceptions ,ay occur &here are given some scenarios where unchec!ed exceptions can occur. &hey are as follows? 14 7cenario 'here ArithmeticException occurs If we divide any number by zero, there occurs an ArithmeticException. view plain print @ ). int aA<,B,CBBArithmetic.xception 24 7cenario 'here NullPointerException occurs If we have null value in any variable, performing any operation by the variable occurs an NullPointerException. view plain print @ ). 'tring sAnullC 7. 'ystem.out.println(s.length(CBB4ull$ointer.xception 4 7cenario 'here NumberFormatException occurs &he wrong formatting of any value, may occur NumberFormatException. 'uppose I have a string variable that have characters, converting this variable into digit will occur NumberFormatException. view plain print @ ). 'tring sA0abc0C 7. int iAInteger.parseInt(sCBB4umber5ormat.xception "4 7cenario 'here ArrayIndexOutOfBoundsException occurs If you are inserting any value in the wrong index, it would result ArrayIndexOutOfBoundsException as shown below? view plain print @ ). int aDEAnew intD<EC 7. aD),EA<,C B BArrayIndex1ut1f3ounds.xception ClassCastException &hrown to indicate that the code has attempted to cast an ob2ect to a subclass of which it is not an instance. 5or example, the following code generates a ClassCastException? Object x = ne Integer!"#$ %ystem&out&println!!%tring#x#$
7.#o thro' thro's ) throw is used to explicitly throw an exception. throws is used to declare an exception. 7 chec!ed exception cannot be propagated without throws. chec!ed exception can be propagated with throws. 8 throw is followed by an instance. throws is followed by class. : throw is used within the method. throws is used with the method signature. < Fe cannot throw multiple exception Fe can declare multiple exception e.g. public void method( throws I1.xception, 'G(.xception. Fhat are .xceptions &ypes of >ava .xceptions .xception #lasses Important methods in the &hrowable class "andling .xceptions 6eclaring custom .xception