Exception Handling

In Java, exception handler acts as a flag to catch an error and makes the program run smoothly. When an error is encountered during execution of a program, an exception is said to have occurred. This disrupts the program. A compile-time error happens when the program is being compiled. Generally, compile-time errors are syntax errors; and they are caught by the compiler. A run time error occurs during the execution of a program. Exception handling is the process of responding to anomalous occurrence or exceptional events during execution of a program. The two types of errors are compile time errors and runtime errors. Compile time errors are a result out of violation of programming language’s grammar rules. They are caught by java compiler. Run time errors occur when program with no syntax errors asks the computer to do something that computer is unable to reliably do. Exception handling clarifies code and enhances readability. It simulates consequences, as error handling takes place at one place and in one manner. Exception handling makes clear-robust and fault-tolerant programs. Java uses try-catch-finally syntax to test section of code and to trap error, if any error occurs in that region. The finally keyword can be used to provide a block of code that is always performed regardless of whether an exception is signaled or not.

To Access the full content, Please Purchase

  • Q1

    Name the block used to catch exceptions.

    Marks:1
    Answer:

    Try block is used to catch exceptions.

    View Answer
  • Q2

    What is the role of exception handling?

    Marks:1
    Answer:

    Exception Handlind is a way to handle anomalous situation in a program by adding the error handling code. Exception handling separates error-handling from the normal code.

    View Answer
  • Q3

    What are the keywords used for exception handling in Java?

    Marks:1
    Answer:

    Java handles exceptions using five keywords-try, catch, finally, throws and throw.

    View Answer
  • Q4

    What are two types of errors?

    Marks:1
    Answer:

    The two types of errors are:
    i)Compile-time errors ii) Run-time errors

    View Answer
  • Q5

    Define the term exception.

    Marks:1
    Answer:

    An exception is an unusual condition which may occur during the execution of a program.

    View Answer