Created
December 4, 2015 10:35
-
-
Save ProZhar/b50b1dbe96c64a4421c5 to your computer and use it in GitHub Desktop.
com.javarush.test.level09.lesson08.task05
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.task05; | |
| /* Перехват unchecked исключений | |
| В методе processExceptions обработайте все unchecked исключения. | |
| Нужно вывести стек-трейс каждого возникшего исключения используя метод printStack. | |
| Можно использовать только один блок try.. | |
| */ | |
| public class Solution | |
| { | |
| public static void main(String[] args) { | |
| processExceptions(new Solution()); | |
| } | |
| public static void processExceptions(Solution obj) { | |
| try | |
| { | |
| obj.method1(); | |
| obj.method2(); | |
| obj.method3(); | |
| } | |
| catch (Exception e) | |
| { | |
| printStack(e); | |
| } | |
| } | |
| public static void printStack(Throwable throwable) { | |
| System.out.println(throwable); | |
| for (StackTraceElement element : throwable.getStackTrace()) { | |
| System.out.println(element); | |
| } | |
| } | |
| public void method1(){ | |
| throw new NullPointerException(); | |
| } | |
| public void method2() { | |
| throw new IndexOutOfBoundsException(); | |
| } | |
| public void method3() { | |
| throw new NumberFormatException(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment