Saturday, May 11, 2019

what will be the console output when you run the following code?

Problem statement:
what will be the output of the following exception handling code?
  1. public class ExecutionSix {
  2.     public static void throwIt() 
  3.     {
  4.         throw new RuntimeException();
  5.     }
  6.     public static void unsafe() 
  7.     {
  8.         try 
  9.         {
  10.             System.out.println("Unsafe try start !");
  11.             throwIt();
  12.             System.out.println("Unsafe try end !");
  13.         } finally 
  14.         {
  15.             System.out.println("Finally executing !");
  16.         }
  17.     }
  18.     public static void main(String[] args) 
  19.     {
  20.         try 
  21.         {
  22.             unsafe();
  23.         } catch (RuntimeException e) 
  24.         {
  25.             System.out.println("Exception caught !");
  26.         }
  27.     }
  28. }
Output:
Unsafe try start !
Finally executing !
Exception caught !

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...