// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.lang.reflect.InvocationTargetException;

public class Exceptional {
    public static Exception fac() {
        return new YException();
    }
    public static void test1() throws XException {
        Exception ex = fac();
        throw (XException)ex;
    }
    public static void test2() throws XException {
        try {
            Exceptional.class.getMethod("m").invoke(null);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
    public static void m() throws YException {
        throw new YException();
    }
    public static void main(String[] args) {
        try {
            test1();
        } catch (XException e) {
            System.out.println("Checked");
            e.printStackTrace();
        } catch(RuntimeException e) {
            System.out.println("Unchecked");
            e.printStackTrace();
        }
        try {
            test2();
        } catch (XException e) {
            System.out.println("Checked");
            e.printStackTrace();
        } catch(RuntimeException e) {
            System.out.println("Unchecked");
            e.printStackTrace();
        }
    }
}

class XException extends Exception {
}

class YException extends Exception {
}
