<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/** 
 * FlameThrower class demonstating use of exceptions
 * Notes: Notice the use of an inner class (Flame) here.  Since this is 
 * an inner class I don't need a seperate file for it.  Also, notice that
 * flameThrowerCaller MUST declare that it may throw Flame since it calls
 * something which may throw Flame.
 */
public class FlameThrower {
    private static final int HOT = 2;
    private static final int COLD = 1;

    private static class Flame extends Exception {  // Declare a checked exception
	private int temperature = COLD;
	
	private Flame(final int t) { temperature = t; }

	private void burn() {
	    if(temperature == HOT)
		System.out.println("Burnt by a HOT flame.");
	    else
		System.out.println("Burnt by a COLD flame.");
	}
    }	
    
    private static void flameThrower() throws Flame {
	System.out.println("flameThrower-1");
	throw new Flame(HOT); // Flame is a member of class FlameThrower
	// System.out.println("flameThrower-2");
    }

    private static void flameThrowerCaller() throws Flame {  // Need since may throw!
	try {
	    System.out.println("flameThrowerCaller-1");
	    flameThrower();
	    System.out.println("flameThrowerCaller-2");
	} finally {
	    System.out.println("flameThrowerCaller-3");
	}
    }

    public static void main(String[] args) {
	try {
	    System.out.println("main-1");
	    flameThrowerCaller();
	    System.out.println("main-2");
	} catch (Flame f) {
	    f.burn();  // call a private method of the exception object
	} finally {
	    System.out.println("main-3");
	}
	System.out.println("main-4");
    }
}
</pre></body></html>