Java error capture and handling sample of of Java exception capture

  • 2020-04-01 02:44:57
  • OfStack

Here is a small example to verify the error capture.


public class TestCatchError extends Error{

    private static final long serialVersionUID = -351488225420878020L;
    public TestCatchError(){
        super();
    }

    public TestCatchError(String msg){
        super(msg);
    }

    public static void main(String[] args) {
        try {
            throw new TestCatchError("test catch error");
        } catch (Throwable t) {
            System.out.println("step in the catch ~");
            t.printStackTrace();
        }
    }
}

Operation results:


step in the catch ~
TestCatchError: test catch error
at TestCatchError.main(TestCatchError.java:23)


Related articles: