Search in sources :

Example 1 with ExceptionHandler

use of org.rx.exception.ExceptionHandler in project rxlib by RockyLOMO.

the class CoreTester method exceptionHandle.

@ErrorCode
@ErrorCode(cause = IllegalArgumentException.class)
@Test
public void exceptionHandle() {
    ExceptionHandler handler = ExceptionHandler.INSTANCE;
    handler.log(new InvalidException("test error"));
    System.out.println(handler.queryTraces(null, null, null));
    String err = "ERR";
    ApplicationException ex = new ApplicationException(values(err));
    assert eq(ex.getFriendlyMessage(), "Test error code, value=" + err);
    ex = new ApplicationException(values(err), new IllegalArgumentException());
    assert eq(ex.getFriendlyMessage(), "Test IAException, value=" + err);
    $<IllegalArgumentException> out = $();
    assert ex.tryGet(out, IllegalArgumentException.class);
    String errCode = "ERR_CODE";
    ex = new ApplicationException(UserManager.BizCode.USER_NOT_FOUND, values(errCode));
    assert eq(ex.getFriendlyMessage(), "User " + errCode + " not found");
    ex = new ApplicationException(UserManager.BizCode.COMPUTE_FAIL, values(errCode));
    assert eq(ex.getFriendlyMessage(), "Compute user level error " + errCode);
    try {
        Reflects.changeType("x", Date.class);
    } catch (InvalidException e) {
        e.printStackTrace();
    }
}
Also used : ExceptionHandler(org.rx.exception.ExceptionHandler) ApplicationException(org.rx.exception.ApplicationException) InvalidException(org.rx.exception.InvalidException) Test(org.junit.jupiter.api.Test) ErrorCode(org.rx.annotation.ErrorCode)

Aggregations

Test (org.junit.jupiter.api.Test)1 ErrorCode (org.rx.annotation.ErrorCode)1 ApplicationException (org.rx.exception.ApplicationException)1 ExceptionHandler (org.rx.exception.ExceptionHandler)1 InvalidException (org.rx.exception.InvalidException)1