10.4 Calling Methods that Throw Exceptions Flashcards
1
Q
📝️ What PITFALLS when code-snnipet doesn’t throw a checked-exception?
A
✅ We can specify it might throws a checked-exception
❌ However, we can NOT wrap it in a try-catch block (Unreachable catch-block)
2
Q
📝️ What are the PITFALLS when Overriding Methods with Exceptions?
A
✅ Having fewer exceptions is ok
❌ Adding new exceptions (✅Unchecked-exceptions is ok (redundant))
3
Q
📝️ What are the three ways of Printing an Exception?
A
- > System.out.println(exc); //Exception type + message
- > System.out.println(exc.getMessage()); //message
- > exc.printStackTrace(); //hierarchy of method calls