πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      Which of the following is the correct way to handle

      exceptions in Java?
      A try { } error { } handle { } Correct Answer Incorrect Answer
      B handle { } catch { } end { } Correct Answer Incorrect Answer
      C begin { } rescue { } ensure { } Correct Answer Incorrect Answer
      D try { } except { } else { } Correct Answer Incorrect Answer
      E try { } catch(Exception e) { } finally { } Correct Answer Incorrect Answer

      Solution

      Java uses try-catch-finally blocks. The try block contains code that may throw an exception. The catch block handles specific exceptions. The finally block always executes regardless of whether an exception occurred or not. It is used for resource cleanup (closing DB connections, file handles). Option C is Ruby syntax. Option D is Python syntax. The finally block is critical in banking applications to ensure database connections are always properly released.

      Practice Next

      Relevant for Exams:

      ask-question