Search in sources :

Example 6 with VetoException

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

the class ParsingFailedStatusTest method testConstructorWithoutCode.

@Test
public void testConstructorWithoutCode() {
    ProcessingException veto = new VetoException("Foo");
    ParsingFailedStatus status = new ParsingFailedStatus(veto, "Bar");
    assertEquals("Foo", status.getMessage());
    // default value for in members
    assertEquals(0, status.getCode());
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 7 with VetoException

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

the class ParsingFailedStatusTest method testConstructorCopiesCode.

@Test
public void testConstructorCopiesCode() {
    ProcessingException veto = new VetoException("Foo").withCode(123);
    ParsingFailedStatus status = new ParsingFailedStatus(veto, "Bar");
    assertEquals("Foo", status.getMessage());
    assertEquals(123, status.getCode());
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 8 with VetoException

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

the class FormToStore method doIt.

private void doIt(MethodImplementation implementation) {
    switch(implementation) {
        case MARK_NOT_STORED:
            setFormStored(false);
            break;
        case MARK_STORED:
            setFormStored(true);
            break;
        case VETO_EXCEPTION:
            throw new VetoException(VETO_EXCEPTION_TEXT);
        case CONSUMED_VETO_EXCEPTION:
            VetoException vetoException = new VetoException("Implementation throws a consumed VetoException");
            vetoException.consume();
            throw vetoException;
        case DO_NOTHING:
        default:
            // nothing to do
            break;
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 9 with VetoException

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

the class ServiceOperationInvoker method interceptException.

/**
 * Method invoked to intercept a service exception before being put into the {@link ServiceTunnelResponse} to be sent
 * to the client. This method must not throw an exception.
 * <p>
 * <p>
 * Security: do not send back original error and stack trace with implementation details.
 * <p>
 * The default implementation returns an empty exception, or in case of a {@link VetoException} only its title,
 * message, htmlMessage, error code and severity.
 */
protected Throwable interceptException(Throwable t) {
    Throwable p;
    if (t instanceof VetoException) {
        VetoException ve = (VetoException) t;
        p = new VetoException(ve.getStatus().getBody()).withTitle(ve.getStatus().getTitle()).withHtmlMessage(ve.getHtmlMessage()).withCode(ve.getStatus().getCode()).withSeverity(ve.getStatus().getSeverity());
    } else {
        p = new ProcessingException(TEXTS.get("RequestProblem"));
    }
    p.setStackTrace(new StackTraceElement[0]);
    return p;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 10 with VetoException

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

the class ClientExceptionHandler method showExceptionInternal.

protected void showExceptionInternal(final Throwable t) {
    final IClientSession session = ClientSessionProvider.currentSession();
    if (session == null) {
        return;
    }
    if (session.getDesktop() == null || !session.getDesktop().isOpened()) {
        return;
    }
    // Prevent loops while displaying the exception.
    final Semaphore loopDetectionSemaphore = getLoopDetectionSemaphore(session);
    if (loopDetectionSemaphore.tryAcquire()) {
        try {
            // Synchronize with the model thread if not applicable.
            if (ModelJobs.isModelThread()) {
                showException(t);
            } else {
                try {
                    ModelJobs.schedule(new IRunnable() {

                        @Override
                        public void run() throws Exception {
                            showException(t);
                        }
                    }, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExceptionHandling(null, true).withName("Visualizing PlatformException")).awaitDone();
                } catch (final ThreadInterruptedError e) {
                // NOSONAR
                // NOOP
                }
            }
        } finally {
            loopDetectionSemaphore.release();
        }
    } else {
        Exception e = new Exception("Stacktrace and suppressed exception");
        // add original exception for analysis
        e.addSuppressed(t);
        LOG.warn("Loop detection in {}", getClass().getName(), e);
        if (ModelJobs.isModelThread()) {
            IMessageBox msgBox = MessageBoxes.createOk().withSeverity(IStatus.ERROR).withHeader(TEXTS.get("Error"));
            if (t instanceof VetoException) {
                IProcessingStatus status = ((VetoException) t).getStatus();
                msgBox.withHeader(status.getTitle()).withBody(status.getBody());
            }
            msgBox.show();
        }
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IProcessingStatus(org.eclipse.scout.rt.platform.exception.IProcessingStatus) IClientSession(org.eclipse.scout.rt.client.IClientSession) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) Semaphore(java.util.concurrent.Semaphore) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IMessageBox(org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)

Aggregations

VetoException (org.eclipse.scout.rt.platform.exception.VetoException)16 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)6 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)3 Test (org.junit.Test)3 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)2 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Semaphore (java.util.concurrent.Semaphore)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 IPageWithNodes (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes)1 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)1 IValidateContentDescriptor (org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor)1 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)1 IProcessingStatus (org.eclipse.scout.rt.platform.exception.IProcessingStatus)1 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)1 ProcessingStatus (org.eclipse.scout.rt.platform.exception.ProcessingStatus)1