0% found this document useful (0 votes)
40 views4 pages

Java Exception Handling Examples

The document contains a request to edit a Word file and includes code examples for handling exceptions in Java using try, catch, and throw. It demonstrates three types of exceptions: ArithmeticException, ArrayIndexOutOfBoundsException, and IOException, with corresponding code snippets and outputs. Each code example illustrates how to catch and handle the specific exception type effectively.

Uploaded by

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

Java Exception Handling Examples

The document contains a request to edit a Word file and includes code examples for handling exceptions in Java using try, catch, and throw. It demonstrates three types of exceptions: ArithmeticException, ArrayIndexOutOfBoundsException, and IOException, with corresponding code snippets and outputs. Each code example illustrates how to catch and handle the specific exception type effectively.

Uploaded by

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

Its my humble request please edit this

Word File And Paste the Screen Shot of


your Output that you performed in your
Compiler.

Question 1
10 Points

Write a program to handle an exception using try, catch and throw.

CODE : -

Arithmetic Exception

class third
{
public static void main(String[]args)
{
int a=10;
int b=0;
try
{
int c=a/b;
[Link]("C = "+ c);
}
catch(ArithmeticException obj)
{
[Link]("It handle's the Arithmetic Exception");
}
}
}

OUTPUT : -
CODE : -

ArrayIndexOutOfBoundsException

class student
{
public static void main(String[]args) throws Exception
{
int x[] = new int[10];

try
{
[Link](x[11]);
}
catch(ArrayIndexOutOfBoundsException obj1)
{
[Link]("It Handle's "
+ "ArrayIndexOutOfBoundsException");
}

}
}

OUTPUT : -
CODE : -

IOException

import [Link];

class third
{
public static void main(String[]args)
{

try
{
throw new IOException();
}
catch(IOException obj1)
{
[Link]("It Handle's IOException");
}

}
}

OUTPUT : -

You might also like