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());
}
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());
}
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;
}
}
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;
}
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();
}
}
}
Aggregations