Exceptions


  1. What is the output of this program?
    public class exception_handling 
    {
    public static void main(String args[])
    {
    try
    {
    int p, q;
    q = 0;
    p = 5 / q;
    System.out.print("Love");
    }
    catch(ArithmeticException e)
    {
    System.out.print("You");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    You


  1. Which of these keywords is used to manually throw an exception?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    throw



  1. What is the output of this program?
    public class exception_Example
    {
    public static void main(String args[])
    {
    try
    {
    System.out.print("Interview" + " " + 15 / 0);
    }
    catch(ArithmeticException e)
    {
    System.out.print("Mania");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    System.ou.print() function first converts the whole parameters into a string and then prints, before “Interview” goes to output stream 15 / 0 error is encountered which is cached by catch block printing just “Mania”.


  1. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    If an exception occurs within the try block, it is thrown and cached by catch block for processing.



  1. What is the output of this program?
     public class exception_Example
    {
    public static void main(String args[])
    {
    try
    {
    int p, q;
    q = 0;
    p = 13 / q;
    System.out.print("welcome to");
    }
    catch(ArithmeticException e)
    {
    System.out.print("Interview");
    }
    finally
    {
    System.out.print(" Mania");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    finally keyword is used to execute the code before try and catch block end.