重新抛出异常

异常处理

void methodWithException() throws Exception {
    try {
        throw new Exception("test exception");
    }
    catch (Exception e) {
        //实现任意部分处理,
        //并把错误传给调用方代码
        throw e;
    }
}

try {
    methodWithException();
}
catch (Exception e) {
    System.out.println(e.getMessage());
}