Search in sources :

Example 1 with ExceptionHandler

use of org.eclipse.scout.rt.platform.exception.ExceptionHandler in project scout.rt by eclipse.

the class ExceptionProcessorTest method testWithCustomExceptionHandler.

@Test
public void testWithCustomExceptionHandler() throws Exception {
    final RuntimeException exception = new RuntimeException("expected JUnit test exception");
    final AtomicReference<Throwable> error = new AtomicReference<>();
    JobInput jobInput = Jobs.newInput().withExceptionHandling(new ExceptionHandler() {

        @Override
        public void handle(Throwable t) {
            error.set(t);
        }
    }, true);
    CallableChain<String> chain = new CallableChain<>();
    chain.add(new ExceptionProcessor<String>(jobInput));
    chain.call(new Callable<String>() {

        @Override
        public String call() throws Exception {
            throw exception;
        }
    });
    assertSame(exception, error.get());
    verify(m_exceptionHandler, never()).handle(eq(exception));
}
Also used : CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobInput(org.eclipse.scout.rt.platform.job.JobInput) ExceptionHandler(org.eclipse.scout.rt.platform.exception.ExceptionHandler) Test(org.junit.Test)

Example 2 with ExceptionHandler

use of org.eclipse.scout.rt.platform.exception.ExceptionHandler in project scout.rt by eclipse.

the class ThrowHandledExceptionStatement method evaluate.

@Override
public void evaluate() throws Throwable {
    m_next.evaluate();
    // Re-throw the first handled exception if 'JUnitExceptionHandler' is installed as exception handler.
    final ExceptionHandler exceptionHandler = BEANS.get(ExceptionHandler.class);
    if (exceptionHandler instanceof JUnitExceptionHandler) {
        ((JUnitExceptionHandler) exceptionHandler).throwOnError();
    }
}
Also used : ExceptionHandler(org.eclipse.scout.rt.platform.exception.ExceptionHandler) JUnitExceptionHandler(org.eclipse.scout.rt.testing.platform.runner.JUnitExceptionHandler) JUnitExceptionHandler(org.eclipse.scout.rt.testing.platform.runner.JUnitExceptionHandler)

Aggregations

ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)1 JobInput (org.eclipse.scout.rt.platform.job.JobInput)1 JUnitExceptionHandler (org.eclipse.scout.rt.testing.platform.runner.JUnitExceptionHandler)1 Test (org.junit.Test)1