Created
December 4, 2015 09:48
-
-
Save ProZhar/d01d05d90ea2eaa6dc91 to your computer and use it in GitHub Desktop.
com.javarush.test.level09.lesson08.task01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.javarush.test.level09.lesson08.task01; | |
| import java.io.FileNotFoundException; | |
| import java.net.URISyntaxException; | |
| /* Исключения | |
| Есть метод, который выбрасывает два исключения, унаследованные от Exception, и два унаследованных от RuntimeException: | |
| NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException. | |
| Нужно перехватить NullPointerException и FileNotFoundException, но не перехватывать | |
| ArithmeticException и URISyntaxException. Как это сделать? | |
| */ | |
| public class Solution | |
| { | |
| public static void main(String[] args) throws ArithmeticException, URISyntaxException | |
| { | |
| try | |
| { | |
| method1(); | |
| } | |
| catch (NullPointerException | FileNotFoundException e) | |
| { | |
| System.out.println(e); | |
| } | |
| } | |
| public static void method1() throws NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException | |
| { | |
| int i = (int) (Math.random() * 4); | |
| if (i == 0) | |
| throw new NullPointerException(); | |
| if (i == 1) | |
| throw new ArithmeticException(); | |
| if (i == 2) | |
| throw new FileNotFoundException(); | |
| if (i == 3) | |
| throw new URISyntaxException("", ""); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment