Created
April 24, 2015 18:08
-
-
Save ZhdanRuslan/b4b14723f3465e18c722 to your computer and use it in GitHub Desktop.
com.javarush.test.level09.lesson08.task01
This file contains 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; | |
import java.util.HashMap; | |
/* Исключения | |
Есть метод, который выбрасывает два исключения, унаследованные от Exception, и два унаследованных от RuntimeException: | |
NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException. | |
Нужно перехватить NullPointerException и FileNotFoundException, но не перехватывать | |
ArithmeticException и URISyntaxException. Как это сделать? | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
try{ | |
method1(); | |
} catch (NullPointerException exc){ | |
System.out.println(exc); | |
} catch (FileNotFoundException exc){ | |
System.out.println(exc); | |
} finally { | |
System.out.println("finalized..."); | |
} | |
} | |
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