Advertisement
apl-mhd

TryCatchNestedFinally

Jan 10th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package summer2017;
  2.  
  3. import java.util.InputMismatchException;
  4.  
  5. public class Test {
  6.  
  7.  
  8.     static void display() {
  9.  
  10.         if (1 == 1)
  11.             throw new InputMismatchException("Error");
  12.     }
  13.  
  14.  
  15.     public static void throwException(int num) {
  16.         if (num % 2 == 0)
  17.             throw new InputMismatchException("Can't be an even number.");
  18.  
  19.         if (num == 5)
  20.             throw new InputMismatchException("Can't be multiple of five");
  21.  
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         try {
  26.  
  27.  
  28.             try {
  29.                 throwException(4);
  30.             } catch (InputMismatchException e) {
  31.                 System.out.println(e.getMessage());
  32.  
  33.                 throwException(5);
  34.             } finally {
  35.                 System.out.println("aaa");
  36.             }
  37.         }
  38.         catch (InputMismatchException e){
  39.             System.out.println("aa"+e.getMessage());
  40.         }
  41.  
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement