Question from the test. (my option is bold) Can one catch block deal with handling and exceptions like NullPointerException, and IOException?
- Yes
- Not
Question from the test. (my option is bold) Can one catch block deal with handling and exceptions like NullPointerException, and IOException?
To solve such questions, you should have a test class and a little desire to figure it out yourself:
import java.io.IOException; public class ExceptionTest { public static void main(String[] args) { try { nullPointerException(); iOException(); } catch (Exception ex) { System.out.println(ex.getClass().getName()); } } private static void nullPointerException() { throw new NullPointerException(); } private static void iOException() throws IOException { throw new IOException(); } } I will push you a little ...
catch (NullPointerException | IOException ex) But the answer is really easy to google, checked on request "several exceptions in one catch" - the first link. - UratySource: https://ru.stackoverflow.com/questions/813591/
All Articles