Skip to content

Use pattern matching in ExceptionStash #917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Syntevo and others.
* Copyright (c) 2021, 2023 Syntevo and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -59,12 +59,12 @@ public void stash(Throwable throwable) {
try {
Display display = Display.getCurrent ();
if (display != null) {
if (throwable instanceof RuntimeException) {
display.getRuntimeExceptionHandler().accept((RuntimeException)throwable);
if (throwable instanceof RuntimeException runtimeEx) {
display.getRuntimeExceptionHandler().accept(runtimeEx);
/* If handler doesn't throw then the exception is fully handled */
return;
} else if (throwable instanceof Error) {
display.getErrorHandler().accept((Error)throwable);
} else if (throwable instanceof Error er) {
display.getErrorHandler().accept(er);
/* If handler doesn't throw then the exception is fully handled */
return;
}
Expand All @@ -88,10 +88,10 @@ public void close() {
Throwable throwable = storedThrowable;
storedThrowable = null;

if (throwable instanceof RuntimeException) {
throw (RuntimeException)throwable;
} else if (throwable instanceof Error) {
throw (Error)throwable;
if (throwable instanceof RuntimeException runtimeEx) {
throw runtimeEx;
} else if (throwable instanceof Error er) {
throw er;
}
}

Expand Down