[go: up one dir, main page]

0% found this document useful (0 votes)
2 views16 pages

Exception Handling

The document discusses exception handling in Java, explaining the difference between checked and unchecked exceptions. Checked exceptions must be handled at compile-time, while unchecked exceptions occur at runtime and are not checked during compilation. It also provides examples of both types of exceptions and references for further reading.

Uploaded by

siddiquisam9897
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Exception Handling

The document discusses exception handling in Java, explaining the difference between checked and unchecked exceptions. Checked exceptions must be handled at compile-time, while unchecked exceptions occur at runtime and are not checked during compilation. It also provides examples of both types of exceptions and references for further reading.

Uploaded by

siddiquisam9897
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Exception Handling

In Java

Ms. Neelam Yadav


Assistant Professor
Department of Computer Applications
Exception Handling

Errors:
Handled to create reliable applications
Result of application bugs
Beyond the control of the application
Exceptions:
An error that occurs at runtime
Abnormal behavior that leads to unpredictable result
Disrupts the normal flow of application execution
Exception Handling

java.lang.Throwable class:
Parent class of all exceptions, as shown in the following figure.
Categories of Exceptions

Main categories of exceptions:


Unchecked exceptions
Checked exceptions
Checked Exceptions

• Checked exceptions are checked at compile-time.


• It means if a method is throwing a checked exception then it should handle
the exception using try-catch block or it should declare the exception
using throws keyword, otherwise the program will give a compilation error.
• It is named as checked exception because these exceptions are checked at
Compile time.
Checked Exceptions

Here are the few other Checked Exceptions –


• SQLException
• IOException
• DataAccessException
• ClassNotFoundException
• InvocationTargetException
Checked Exceptions
import java.io.*;
public class useBuffRead
{
public static void main(String[] as) throws IOException
{
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string ");
s=br.readLine();
System.out.println("Name"+s);
}}
Unchecked Exceptions

• Unchecked exceptions are not checked


at compile time. It means if your
program is throwing an unchecked
exception and even if you didn’t
handle/declare that exception, the
program won’t give a compilation error.
• All Unchecked exceptions are direct sub
classes of RuntimeException class.
Exception Handling

Unchecked exceptions:
java.lang.RuntimeException
java.lang.Error
Occur during the execution of
application &discovered by using the
try-catch statement
Some RuntimeExceptions:
ArrayIndexOutOfBoundsException
NullPointerException
ArithmeticException
Unchecked Exceptions

public class err21


{
public static void main(String[] args)
{
String a1="preeti";
int a[]=new int[]{4,5,6,7,8};
int i;
for(i=0; i<7; i++) Ex
cepti
{ on O
ccur
System.out.println(a[i]); s
}}}
Unchecked Exceptions
Unchecked Exceptions

public class err


{
public static void main(String[] args)
{
int a,b,c;
a=30;
b=0; Exception Occurs
c=a/b;
System.out.println(c);
}
}
Unchecked Exceptions
Disclaimer (Calibri, font size 40-44)
References

Text Books:
Kanetkar Y., “Let Us C”, BPB Publications.
Schildt H., “C- The Complete Reference”, McGraw-Hill.

Web references:
https://www.programiz.com/c-programming
https://www.w3schools.com/c/c_intro.php
https://www.geeksforgeeks.org/c-programming-language/
https://www.tutorialspoint.com/cprogramming/index.htm
Thank You

You might also like