FileDocCategorySizeDatePackage
ThrowsUnchecked.javaAPI DocExample946Sat Nov 25 12:55:48 GMT 2000None

ThrowsUnchecked

public 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.

Fields Summary
Constructors Summary
Methods Summary
public voiddoTheWork()
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 voidmain(java.lang.String[] argv)

		new ThrowsUnchecked().doTheWork();
	
public inttestit(java.lang.String input)
Model of a method that might throw an unchecked exception.

exception
NumberFormatException if called with value 1.

		return Integer.parseInt(input);