Exception in java
Exception has two types. Unchecked Exception and Checked Exception.
IOException
ClassNotFoundException
CloneNotSupportedException
IllegalAccessException
InterruptedException
NoSuchFieldException
NoSuchMethodException
These are Checked Exception.
Can you explain each exception with simple example(Error program and correction program)?
IOException
ClassNotFoundException
CloneNotSupportedException
IllegalAccessException
InterruptedException
NoSuchFieldException
NoSuchMethodException
These are Checked Exception.
Can you explain each exception with simple example(Error program and correction program)?
Replies
-
Anoop KumarChecked Exception: You must have to handle those exceptions by yourself using try-catch or throws clause
Unckecked: JRE will take care of these things
Why Checked Exception: In case of IOException, for example you wrote a program to read a file. How can java know if file is there to read? that is why it insist you to catch this exception by yourself.
Java is telling you that somewhere it could be wrong.
Rest, explaining each exception will be a theory , I would suggest you to write programs in which these exception can occur. If will give you live practical example. -
krishbcs
thanks but i need detail each exception with examples.ianoopChecked Exception: You must have to handle those exceptions by yourself using try-catch or throws clause
Unckecked: JRE will take care of these things
Why Checked Exception: In case of IOException, for example you wrote a program to read a file. How can java know if file is there to read? that is why it insist you to catch this exception by yourself.
Java is telling you that somewhere it could be wrong.
Rest, explaining each exception will be a theory , I would suggest you to write programs in which these exception can occur. If will give you live practical example. -
krishbcsfor example:
ArithmeticException:
Error program:
class ArithException
{
public static void main(String arg[])
{
System.out.println(2/0);
}
}
Output: ArithmeticException Error.
Correction Program:
class ArithException
{
public static void main(String arg[])
{
try{
System.out.println(2/0);
}catch(ArithmeticException)
{ System.out.println("divide by zero is not valued");
}
}
Ouptut: Divide by zero is not Valued.
I need like this for every exception.
would you help me?
You are reading an archived discussion.
Related Posts
I want to know what is multi thread in java? I am a computer science engineer. I want to know about it in detail and not just the technical definition....
I’ve heard someone talked about infrastructure construction. They talked of hatch function in road design. But I don’t know much about road design. I’m wondering are there anyone who familiar...
A meeting between a four legged predator and a four wheeled photographer!
So far robots have been slated as rescuers, hazardous zone workers and such . This one shows a...
World's leading auto-makers are getting ready for the Geneva Auto Show in March 2012. The Buggati Veyron has maintained the crown for the fastest production car in the world record...
Lately I have been reading lots of experiences working in Indian IT companies. All of these are service based & which are majority in taking up grads in campus jobs...