5.8) Can a try block be followed only by a finally block?


public class NoCatchOnlyFinally {
	public static void main(String[] args) {
		String name = null;
		try {
			System.out.println("Try block : open resource 1");
			System.out.println("Try block : open resource 2");
			System.out.println("in try :" + name.length());
			System.out.println("Try block : close resources");
		} finally {
			System.out.println("finally : close resources");
		}
	}
}Output:

Previous5.7) What happens if a finally block modifies the value returned from a catch block?Next5.9) Does the order of the exceptions caught in the catch blocks matter?
Last updated
Was this helpful?
