ya_zay4eg

level09.lesson08.task01

Jan 13th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package com.javarush.test.level09.lesson08.task01;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.net.URISyntaxException;
  5. import java.util.HashMap;
  6.  
  7. /* Исключения
  8. Есть метод, который выбрасывает два исключения, унаследованные от Exception,
  9.  
  10. и два унаследованных от RuntimeException:
  11. 1) NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException.
  12.  
  13. Нужно перехватить NullPointerException и FileNotFoundException,
  14.  
  15. но не перехватывать
  16. ArithmeticException и URISyntaxException. Как это сделать?
  17. */
  18.  
  19. public class Solution
  20. {
  21.     public static void main(String[] args) throws Exception
  22.     {
  23.         //Напишите тут ваш код
  24.         try
  25.         {
  26.             method1();
  27.         }
  28.  
  29.  
  30.  
  31.         //Напишите тут ваш код
  32.         catch (NullPointerException e){
  33.  
  34.         }
  35.         catch (FileNotFoundException e){
  36.  
  37.         }
  38.  
  39.     }
  40.  
  41.     public static void method1() throws NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException
  42.     {
  43.         int i = (int) (Math.random() * 4);
  44.         if (i == 0)
  45.             throw new NullPointerException();
  46.         if (i == 1)
  47.             throw new ArithmeticException();
  48.         if (i == 2)
  49.             throw new FileNotFoundException();
  50.         if (i == 3)
  51.             throw new URISyntaxException("", "");
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment