Search in sources :

Example 1 with IProcessingStatus

use of org.eclipse.scout.rt.platform.exception.IProcessingStatus 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

Semaphore (java.util.concurrent.Semaphore)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)1 IProcessingStatus (org.eclipse.scout.rt.platform.exception.IProcessingStatus)1 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)1 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)1 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)1 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)1