Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
9 views
17 pages
Java Topics
java file
Uploaded by
Naresh 46
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save java topics For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
9 views
17 pages
Java Topics
java file
Uploaded by
Naresh 46
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save java topics For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save java topics For Later
You are on page 1
/ 17
Search
Fullscreen
ANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES TIRUPATKAUTONOMOUS) Emerging Technology(AIML) A.Y#2023-2024 Seminar on EXCEPTION HANDLING Seminar By: Name + LKAVYA Head Of the Department Dr. C. Siva Balaji Re Under the Guidance of Sec:O1 Mr. D NAGA BHUSHANAM GARU, M, Te Department of Al ATS, Tirupati Assistant Professor Department of CSEContents \\ S85 8 8 See ra What is an Exception ? terme es te Hierarchy of Java Exception classes Java Exception Handling Keywords oR e Ses Internal working of java try-catch block ised eee Java Multi Catch block The Throws / Throw Keywords The finally block Common scenarios where exceptions may occur RY eee (alee ses ee hse Ld User-defined Exceptions:What is an exception? ee SEE ues ENE Rue eeu UC Rhee Ue ce Cy SUR CE Seo ee ae uml lr) Pate anu re Me Ue cee ee Reo elie a 10, SQL, Remote etc. U Advantage of Exception Handling Beene eee CU eee RUC CURR Riek mlm Precise CUE A eR ALOR ure] that is why we use exception handling.Realtime Example of Exception in Java 1. Suppose you are watching a video on Youtube, suddenly, internet connectivity is disconnected or not working. In this case, you are not able to continue watching the video on Youtube. This interruption is nothing but an exception. -@-> 8 a Exception A git is watching a video on Interrupted in watching ‘Youtube on the computer video due to internet disconnectivity suddenly Stopped ————P ca > Puncture repaired ee Exception Handled Exception Fig: Realtime Example of Exception Handlinglt sag THROWABLE ERRORS EXCEPTIONS CHECKED EXCEPTION UNCHECKED EXCEPTIError vs Exception ’ Errors: An error represents a OU COM SECT MeO MALT Le team rene tle) carver SIUM oe am CoRe Te Virtual Machine Error MO A ~ Stack overflow Mee Mee ee) Cae ai Crea atta ee ol MAU Stee SUN anmrce ene applications should (rat Array index out of bounds Arithmetic errors (divide by zero Null Pointer Exception W/O ExceptionsInternal working of java try-catch block | An object of exception class is thrown int data = 10/0; fi eer Exception object y ai) NO Rest of code is executedJava Multi Catch block public class TestMultipleCatchBlock{ public static void main(String args{}){ Ze int a[J=new int[5); Exo } {System.out.printIn("task1 is completed");} {System.out.printin("task 2 completed");} {System.out.printin("common task completed");} System.out.printin("rest of the code..."); } } ata time only one Exception is occurred and at a time only one catch te ae av OAll catch blocks must be ordered from most specific to most general i.e. eee me aaa ea ee ek ee eethrow keyword > throw : © Used to explicitly throw an exception @ Can be used to throw checked, unchecked and custom exception tlic clans Testthrow Output: stan woud abate it age ages) [Ceception in tomad mn java ang AnthmencEaception nat vad rrom nem AnthenetEacaption( net vai") ‘System out printin( welcome to vote") ) uh sat vod main(String arya]. wade) ‘System out printing vest ofthe code") > >throws keyword — > throws : @ Used to declare an exception @ Gives an information to the programmer that there may occur an exception so it is better for the programmer to provide the exception handling code so that normal flow can be maintained. lmport java io AOE xception; aes Vesttnrows{ void seconsMetnot() throws IOExCEStON { vom nem 10Exception("dewce error").// Checked exception Cxtoet > svcepton need oid fraebethoat) throws 1OExcegtION { ermal tow seconditethod) > Public static void main final String angst) { {hnal Testthrows cb = new Testtrvoms(); we by firsts); > catch (final Excaption &) ¢ System ou pritin( “exception handled"); > ‘System out printin(“ncema flow." >finally block > Follows a try block. > Always executes, whether or not an exception has occurred. Allows you to run any cleanup-type statements that you want to execute, no matter what happens in the protected code. > Executes right before the return executes present in try block, ‘Syntax of try-finally block: teyt // Protected Code that may throw exception Keatch(Exception ex)( // Catch block may or may not execute Hinaty{ 1/ The finally block always executes.Common scenarios where exceptions may occur | Ser lile =bCell Loli melee ey int a=50/0 /ArithmeticException Belin claas cell lel Melero ed String s=null System.out.printin(s.length()) /NullPointerException * NumberFormatException occurs String s="abc" int i=Integer.parselnt(s) NumberFormatException * ArraylndexOutOfBoundsException occurs =new int[5]Types of Exceptions — Checked Exceptions @ Checked at compile time Must be either handled or specified using throws keyword > Unchecked Exceptions Not checked at compile time @ Also called as Runtime ExceptionsChecked Exception Example h® > import java.io.*; class Main { public static void main(Stringl} args) { FileReader file = new FileReader("a.txt"); BufferedReader fileinput = new BufferedReader(file); q } > Compilation Error: Exception in thread “main” java.lang.RuntimeException: Uncompilable source code unreported exception jova.io.FileNotFoundException; must be caught or declored to be thrown at Main.main(Mainjava:5)Runtime Exception Example B® > class Main { public static void main(String args[]) { int int y = 10; int 2 = y/x; } } > Exception in thread ~— "main" —_java.lang.ArithmeticException: / by —_ zero at Main.main(Main,java:5) Java Result: 1User-defined Exceptions: | Axe etc el me ele BE my Rea Rel lO rir 4 points in mind when writing your own exception classes. PN Ro ese ieee Rell Rem ice ele) (om DRM a OR Ce Rearecem emul ace ice lee] ig enforced by the Handle or Declare Rule, you need to extend the Latest ma Con DAR CURR Ce Meo elm el Rue R ck c ue R Cl) Tes ce eee oe We can define our own Exception class as below: Eis ee tues eo weTHANK YOU HAVE A NICE DAY!
You might also like
Unit 5
PDF
100% (1)
Unit 5
18 pages
Java Unit 2
PDF
No ratings yet
Java Unit 2
208 pages
Exception Handling
PDF
No ratings yet
Exception Handling
38 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
22 pages
UNIT-5 Handling Error/Exceptions: Try Block
PDF
No ratings yet
UNIT-5 Handling Error/Exceptions: Try Block
11 pages
Exception Handling
PDF
No ratings yet
Exception Handling
8 pages
Exception in Java
PDF
No ratings yet
Exception in Java
6 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
19 pages
9 Exception
PDF
No ratings yet
9 Exception
33 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
18 pages
Java Exception Handling Notes
PDF
No ratings yet
Java Exception Handling Notes
31 pages
Exception Handling
PDF
No ratings yet
Exception Handling
16 pages
Object Oriented Concepts Using Java Unit 4
PDF
No ratings yet
Object Oriented Concepts Using Java Unit 4
18 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
23 pages
OOP Chapter IV
PDF
No ratings yet
OOP Chapter IV
18 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
49 pages
Unit - III
PDF
No ratings yet
Unit - III
38 pages
Chapter 3
PDF
No ratings yet
Chapter 3
11 pages
Java Unit 3 Notes
PDF
No ratings yet
Java Unit 3 Notes
21 pages
Unit 4
PDF
No ratings yet
Unit 4
56 pages
Exception Handling
PDF
No ratings yet
Exception Handling
51 pages
9g Exceptin Handling
PDF
No ratings yet
9g Exceptin Handling
40 pages
Lecture - 13-Exception Handling
PDF
No ratings yet
Lecture - 13-Exception Handling
37 pages
Exception Handling (4) (3436)
PDF
No ratings yet
Exception Handling (4) (3436)
35 pages
Notes Java
PDF
No ratings yet
Notes Java
38 pages
Exception Handling
PDF
No ratings yet
Exception Handling
25 pages
Exception Handling
PDF
No ratings yet
Exception Handling
33 pages
Module 4
PDF
No ratings yet
Module 4
137 pages
Handling Expt .Discussion 1
PDF
No ratings yet
Handling Expt .Discussion 1
5 pages
m3 Java
PDF
No ratings yet
m3 Java
76 pages
Exception Handling
PDF
No ratings yet
Exception Handling
38 pages
Exception Handling and Multithreading: Marks-12
PDF
No ratings yet
Exception Handling and Multithreading: Marks-12
31 pages
Java Exception
PDF
No ratings yet
Java Exception
19 pages
V.exception Handling
PDF
No ratings yet
V.exception Handling
43 pages
Java Exception Handling Module 3
PDF
No ratings yet
Java Exception Handling Module 3
38 pages
OOP Through Java Unit - 3 - Exception Handling
PDF
No ratings yet
OOP Through Java Unit - 3 - Exception Handling
15 pages
Unit 3
PDF
No ratings yet
Unit 3
89 pages
Exception Handling
PDF
No ratings yet
Exception Handling
4 pages
Exceptions New
PDF
No ratings yet
Exceptions New
26 pages
A Seminar On Exception Handlings in Java
PDF
No ratings yet
A Seminar On Exception Handlings in Java
39 pages
Exception Handling in Java
PDF
No ratings yet
Exception Handling in Java
7 pages
Java Unit-3
PDF
No ratings yet
Java Unit-3
69 pages
Exception Handling 2.2.1
PDF
No ratings yet
Exception Handling 2.2.1
10 pages
Exception Handling
PDF
No ratings yet
Exception Handling
28 pages
Exception Handling Module 4
PDF
No ratings yet
Exception Handling Module 4
77 pages
Java M3
PDF
No ratings yet
Java M3
13 pages
Exception Handling
PDF
100% (1)
Exception Handling
21 pages
CH-4 Java - Notes
PDF
No ratings yet
CH-4 Java - Notes
60 pages
Unit 04 Java
PDF
No ratings yet
Unit 04 Java
34 pages
Exception Handling
PDF
No ratings yet
Exception Handling
7 pages
Unit 2 Notes
PDF
No ratings yet
Unit 2 Notes
122 pages
Lecture 13-Exception Handling
PDF
No ratings yet
Lecture 13-Exception Handling
37 pages
Java Unit 3
PDF
No ratings yet
Java Unit 3
34 pages
4 - Exception Handling in Java
PDF
No ratings yet
4 - Exception Handling in Java
12 pages
EXCEPTION
PDF
No ratings yet
EXCEPTION
37 pages
Java UnitII
PDF
No ratings yet
Java UnitII
66 pages
ENotes 1271 Content Document 20250122084854AM
PDF
No ratings yet
ENotes 1271 Content Document 20250122084854AM
10 pages
Java U2
PDF
No ratings yet
Java U2
152 pages
CB2305 Ajp - Unit 3
PDF
No ratings yet
CB2305 Ajp - Unit 3
44 pages