Package com.cedarsolutions.exception.context

Examples of com.cedarsolutions.exception.context.ExceptionContext


    /** Test generateExceptionContext(). */
    @Test public void testGenerateExceptionContext() {
        // This test is very sensitive to line numbers, so if you edit stuff above (even organize imports), this will fail

        ExceptionContext context;
        String expected;

        context = ExceptionUtils.generateExceptionContext(null, 0);
        assertNull(context);

        Exception exception = new Exception("Hello", null);
        context = ExceptionUtils.generateExceptionContext(exception, 0);
        expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:85)";
        assertEquals(expected, context.getLocation());
        assertNotNull(context.getStackTrace());
        assertNull(context.getRootCause());

        Exception cause = new Exception("I am a cause");
        exception = new Exception("Hello", cause);
        context = ExceptionUtils.generateExceptionContext(exception, 0);
        expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:93)";
        assertEquals(expected, context.getLocation());
        assertNotNull(context.getStackTrace());
        assertEquals(ExceptionUtils.generateRootCause(cause), context.getRootCause());

        // note: line number should be marked as if it came from the line below, not the method call
        exception = createException();
        context = ExceptionUtils.generateExceptionContext(exception, 1);
        expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:101)";
        assertEquals(expected, context.getLocation());
        assertNotNull(context.getStackTrace());
        assertNull(context.getRootCause());
    }
View Full Code Here


        assertEquals(null, GwtExceptionUtils.generateStackTrace(null));

        CedarRuntimeException e = new CedarRuntimeException();
        assertNotNull(GwtExceptionUtils.generateStackTrace(e));

        e.setContext(new ExceptionContext());
        assertNotNull(GwtExceptionUtils.generateStackTrace(e));

        e.getContext().setStackTrace("X");
        assertEquals("X", GwtExceptionUtils.generateStackTrace(e));
View Full Code Here

            assertSame(cause, e.getCause());
            assertFalse(e.hasContext());
            assertNull(e.getContext());
        }

        ExceptionContext context = new ExceptionContext();
        CedarException e = new CedarException(message, cause);
        e.setContext(context);
        assertTrue(e.hasContext());
        assertSame(context, e.getContext());
    }
View Full Code Here

            assertSame(cause, e.getCause());
            assertFalse(e.hasContext());
            assertNull(e.getContext());
        }

        ExceptionContext context = new ExceptionContext();
        CedarRuntimeException e = new CedarRuntimeException(message, cause);
        e.setContext(context);
        assertTrue(e.hasContext());
        assertSame(context, e.getContext());
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static <T> T addExceptionContext(Throwable exception, int level) {
        if (exception instanceof IHasExceptionContext) {
            IHasExceptionContext hasContext = (IHasExceptionContext) exception;
            ExceptionContext context = generateExceptionContext(exception, level);
            hasContext.setContext(context);
        }

        return (T) exception;
    }
View Full Code Here

    /** Generate the exception context for an exception. */
    public static ExceptionContext generateExceptionContext(Throwable exception, int level) {
        if (exception == null) {
            return null;
        } else {
            ExceptionContext context = new ExceptionContext();

            context.setLocation(getLocation(exception, level));
            context.setStackTrace(generateStackTrace(exception));
            context.setRootCause(generateRootCause(exception.getCause()));

            return context;
        }
    }
View Full Code Here

TOP

Related Classes of com.cedarsolutions.exception.context.ExceptionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.