Exception handling java


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Exception handling java

  1. 1. EXCEPTION HANDLING Shashwat Shriparv dwwcdbhuhwahegmaltcøm InfinitySOft
  2. 2. ERROKS ERRORS / Campus time Rum time
  3. 3. Compilc Time Errors All syntax errors identified by java eompiler. No class ñle is created when this oecurs. Soitisneeessarytoñxalleompiletime errors for successful eompilation. e. g. Syntax error Use of initialization operator for assignment(= instead of = =
  4. 4. Kuntimc Errors O Some programs may not run successfully dne to wrong logic or errors like stack overllow. E. g. Division by 0. Array index out of bounds Negative array size etc. .
  5. 5. EXCEPTTON O An exception is an event, which occurs during the execution of a program, that disrnpts the normal flow of the program's instructions. O Is defined as a condition that interrnpts the normal flow of operation within a programs
  6. 6. "H *= .:| ,_(›“-. '»'c 3gzeiiuáigiie7lnjeqi“ , im”aiileñiigår i°iltHs4iz/ :,7e| I'|3inil .12 ailtzigaiilx; '4:; z»"| in| $ : .=“. .'-; ai; §_ø1Runa. :my: icñqfisgjtb. Vi' har -zuga j, :§; i;i: i<ai_øi. fuiflt": ,. sgilgiygiáligii/ uxfi] 'nái"zäil_eli'é“_é. :float rà A zeucuqjlr7illz 'to chili ; au n; “itgimx'n'. 'g. u. v_ . X
  7. 7. O For continuing the program execution , the user should try to catch the exception object thrown hy the error condition and then display an appropriate message for taking corrective actions. This task is known as Exception handling
  8. 8. a: v- I i, ' n' , P1 . “i” _. *<'| "7- “v . "l anv" ny. . Ho ' ' v - . â-'r . -f: i:nfiüiläâit. ?Iâiiiiw . sz
  9. 9. in . u-': "»**: . 3.. ':':4'ä'. II. iÖmin1fi »ietiiüflfilllliig n1:'1f| r:_gj:1-. n' *§84* . gat ”J tillit-ii 4] iii »rm 5 enuwq›x= ? j una/ ÅJK' i. . ' . ..ä l gitny
  10. 10. l i i 'l , l . ,.71 i ; L iiiiáiiáiiilailâ-*grs i . .i -Whiiu11_1=; :1i_. $.. .__. i › I
  11. 11. ”sänts : s: jgiuf-“iiis isiømw 'Ian-fi iinniiiäinuu: :inte lilfüi-. iziiå inr r 'i iiaiHltp : wrlliiiai: i i l emiiaauinmin. uaüeäzmágnü-iui *än ñü-*iiaui. ..Hlinelüililui munkarna-i: .#11454 'dihliánlieaulwi
  12. 12. We can display the description o Exception in a println statement hy simply passing the exception as au argument. catch(ArithmeticException ae) l System. out. println(“Exception: ”+ae); i
  13. 13. get/ 'érie5sage(), 'All throwable objects can have an associated error message. Calling this lnessage will return the message if one present. getLoca/ /sed/ éäessagea' gets the localized version Of error IIIGSSElgG. printStaC/ (Tracef): sends the stack trace to the system Console. This is a list of method calls that led to the exception condition. It includes line number and file names. Printing of the stack trace is the default behavior of a runtime eXception when you don°t catch it yourself.
  14. 14. v l . in . p . J'›. ;.VÅ . .›§; =|i, , n. .i r-. s-»u ; in çijfiüjiir 7731;; :. .+'›x. f_'. _l* sassiqiggsiáfatnrai : :;; imn_: s%ra›r-z: u,ii . anslår . witsür iyiitaçtøi-»Liji flliiig-rplllüll 'áijril iáçâra liittisii ilrub- wørirxima» ifgptjjia: .touruixrsüracss : int: ni ti 'ams a gick nu år: ' '-2,5 til! u' i: s li L li: . rJuarr J : QHIAÃKHQLLI : iå: %.iitaj1fa_iji. ; r ranjitailø, ”Elna 111913325 : age: j n: m a (i e. mi, masa u ngr. i u; ugn ei: :;fu_i_u,1-. is : lift : ai: ;ii; iu_r-. ;.: asiatisk. j, i_igig_h, ;
  15. 15. class Ex { public static void main(String dd[]) { int d, a,len; try { | en=0; a=10Ilen; int c[| ={1); c[10]=23; i catch(ArithmeticException e) { System. out. print| n (" division by Zero "+e); i catch (ArraylndexOutOfBoundsException ae) { System. out. print| n ("Array index“ +ae); System. out. print| n("after catch"); i
  16. 16. O In multiple catch statement exception suhclasses must come before any of their super classes. O Because a catch statement that uses a super class will catch exception of that type plus any of its suhclasses. O Thus a subclass would never be reached if it came after its super class.
  17. 17. Nes-ted 'md Try statement can be inside the block of another try. Each try statement in entered, the context of that exception is pushed on the stack . If an inner try cloesn°t have a catch handler for exception , the next try statements catch handlers are inspected. If no catch statements matches then java run time system will handle the exception
  18. 18. Shashwat Sh' rv dwivedishashwa mal. om finitySoft