Skip to content

Instantly share code, notes, and snippets.

@ProZhar
Created December 4, 2015 09:48
Show Gist options
  • Select an option

  • Save ProZhar/d01d05d90ea2eaa6dc91 to your computer and use it in GitHub Desktop.

Select an option

Save ProZhar/d01d05d90ea2eaa6dc91 to your computer and use it in GitHub Desktop.
com.javarush.test.level09.lesson08.task01
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