use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class JmsPublishSubscribeMessageService method initializeService.
@PostConstruct
protected void initializeService() {
try {
@SuppressWarnings("squid:S1149") Hashtable<Object, Object> env = new Hashtable<>();
setupInitialContextEnvironment(env);
InitialContext context = new InitialContext(env.isEmpty() ? null : env);
m_connectionFactory = (ConnectionFactory) context.lookup(CONFIG.getPropertyValue(JndiConnectionFactory.class));
m_destination = (Destination) context.lookup(CONFIG.getPropertyValue(PublishSubscribeTopic.class));
} catch (NamingException e) {
throw new PlatformException("cannot setup jms", e);
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException 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();
}
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class AbstractForm method startInternal.
/**
* This method is called from the implemented handler methods in a explicit form subclass
*/
protected IForm startInternal(final IFormHandler handler) {
ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {
@Override
public void run() throws Exception {
if (isBlockingInternal()) {
throw new IllegalStateException("The form " + getFormId() + " has already been started");
}
// Ensure that boolean is set not only once by the constructor
setFormLoading(true);
setHandler(handler);
m_closeType = IButton.SYSTEM_TYPE_NONE;
m_blockingCondition.setBlocking(true);
try {
initForm();
loadStateInternal();
// if form was disposed during initForm() or loadStateInternal()
if (!isBlockingInternal()) {
return;
}
if (getHandler().isGuiLess()) {
// make sure the form is storing since it is not showing
storeStateInternal();
markSaved();
doFinally();
disposeFormInternal();
return;
}
} catch (RuntimeException | PlatformError e) {
disposeFormInternal();
PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", AbstractForm.this.getClass().getName());
if (pe instanceof VetoException) {
VetoException ve = (VetoException) pe;
interceptOnVetoException(ve, ve.getStatus().getCode());
}
throw pe;
}
setButtonsArmed(true);
setCloseTimerArmed(true);
setFormStarted(true);
// Notify the UI to display this form.
if (isShowOnStart()) {
IDesktop desktop = getDesktop();
if (desktop == null || !desktop.isOpened()) {
throw new ProcessingException("There is no desktop or it is not open in the UI.");
} else {
desktop.showForm(AbstractForm.this);
}
}
}
});
return this;
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class AbstractForm method throwVetoExceptionInternal.
/**
* do not use or override this internal method
*/
protected void throwVetoExceptionInternal(final RuntimeException e) {
PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
if (pe instanceof VetoException && !pe.isConsumed()) {
VetoException ve = (VetoException) pe;
interceptOnVetoException(ve, ve.getStatus().getCode());
// if it was not re-thrown it is assumed to be consumed
ve.consume();
}
throw e;
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class FinalValueTest method testLazySetWithException.
@Test
public void testLazySetWithException() throws Exception {
FinalValue<String> s = new FinalValue<>();
try {
s.setIfAbsent(new Callable<String>() {
@Override
public String call() throws Exception {
throw new Exception("expected JUnit test exception");
}
});
fail("expecting PlatformException");
} catch (PlatformException expected) {
}
}
Aggregations