CrazyEngineers
  • Exception in java

    krishbcs

    krishbcs

    @krishbcs-5tG26c
    Updated: Oct 22, 2024
    Views: 1.1K
    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)?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberFeb 22, 2012

    Checked 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.
    Are you sure? This action cannot be undone.
    Cancel
  • krishbcs

    MemberFeb 23, 2012

    ianoop
    Checked 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.
    thanks but i need detail each exception with examples.
    Are you sure? This action cannot be undone.
    Cancel
  • krishbcs

    MemberFeb 23, 2012

    for 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?
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register