0% found this document useful (0 votes)
17 views3 pages

JavaSession 6

Uploaded by

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

JavaSession 6

Uploaded by

Shivani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---------------------Exception Handling-----------

Runtime Exception :- Arithmatic, Nullpointer, IndexoutOfBound

Ot Excedption :- IO Exception, SQL Exception, class not found Exception

Checked Exception :- Classes that directly inherit throwable class Eg :


IOException, SQLException, Indexoutofbound,

Unchecked Exception :- Rt Exception, Arithmatic Exception Nullpointer,

Some Keywords that are used to handle the Exceptions

try :- try block is used in that part of code where Exception can be occured.

catch :- It catch the Exception and which Exception is occured and print the
messages.

throw :- it is used to throw the Exception to the catch block.

throws :- It is used to define which type of exception can be occured, It is


written besides
the methods.

finally :- It run automatically, It run always(Exceute always).

Syntax:-
try{
//code where Exception can be occured
}
catch(type of Exception)
{
//print mssg }

----------------------------1-------------------
import [Link].*;

import [Link];

public class First {


public static void main(String[] args)
{
// int var1=10, var2=0;
//
// [Link](var1/var2);

// int ar[] = new int[]{4,5,6,7};


// [Link](ar[5]);

// String str=null;
// [Link]([Link]());
}
}
-------------------------2-----------------

import [Link].*;

import [Link];

public class First {


public static void main(String[] args)
{
int var1=10, var2=2;

try {
[Link](var1/var2); }

catch(ArithmeticException e)
{
[Link]([Link]());
}

finally
{
[Link]("It Runs Always");
}

}
}

-----------------------------3----------------------------
import [Link].*;

import [Link];

public class First {


public static void main(String[] args)
{
int var1=10, var2=2;
int ar[] = new int[]{4,5,6,7};

try {
[Link](var1/var2);
[Link](ar[5]); }

catch(IndexOutOfBoundsException | ArithmeticException e)
{
[Link]([Link]());
}

finally
{
[Link]("It Runs Always");
}

}
}

------------------------------4-------------------------

import [Link];
import [Link].*;

import [Link];

public class First {

void f1() throws IOException


{
throw new IOException("Device not found");
}

void f2() throws IOException


{
f1();
}

void calling()
{
try {
f2();
}
catch (Exception e) {
[Link]("Handled");
}
}

public static void main(String[] args)


{
First ob = new First();
[Link]();
[Link]("Tata");

}
}

You might also like