ThrowsUncheckedpublic class ThrowsUnchecked extends Object What happens if a method declares an unchecked exception?
Some people seem to think that declaring a method in a throws
clause is what makes it "checked". As we see here, this is not
the case; checked-ness has only to do with an exception's place
in Java's class inheritance hierarchy. |
Methods Summary |
---|
public void | doTheWork()This method demonstrates calling a method that might throw
an exception, and catching the resulting exception.
String s = " 42";
int i = testit(s); // Note: compiles with no try/catch.
System.out.println("parseit(" + s + ") returned " + i);
| public static void | main(java.lang.String[] argv)
new ThrowsUnchecked().doTheWork();
| public int | testit(java.lang.String input)Model of a method that might throw an unchecked exception.
return Integer.parseInt(input);
|
|