Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static <T extends Throwable> T catchException(Class<T> exceptionClass, Runnable behavior) {
        Throwable caught = null;

        try {
            behavior.run();
        } catch (Throwable ex) {
            caught = ex;
        }

        if (caught != null && exceptionClass.isAssignableFrom(caught.getClass()))
            //noinspection unchecked
            return (T) caught;

        return null;
    }
}