Skip to content

Commit 46bfb2b

Browse files
committed
Use pattern matching in ExceptionStash
1 parent 9e25e9e commit 46bfb2b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/ExceptionStash.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021 Syntevo and others.
2+
* Copyright (c) 2021, 2023 Syntevo and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -59,12 +59,12 @@ public void stash(Throwable throwable) {
5959
try {
6060
Display display = Display.getCurrent ();
6161
if (display != null) {
62-
if (throwable instanceof RuntimeException) {
63-
display.getRuntimeExceptionHandler().accept((RuntimeException)throwable);
62+
if (throwable instanceof RuntimeException runtimeEx) {
63+
display.getRuntimeExceptionHandler().accept(runtimeEx);
6464
/* If handler doesn't throw then the exception is fully handled */
6565
return;
66-
} else if (throwable instanceof Error) {
67-
display.getErrorHandler().accept((Error)throwable);
66+
} else if (throwable instanceof Error er) {
67+
display.getErrorHandler().accept(er);
6868
/* If handler doesn't throw then the exception is fully handled */
6969
return;
7070
}
@@ -88,10 +88,10 @@ public void close() {
8888
Throwable throwable = storedThrowable;
8989
storedThrowable = null;
9090

91-
if (throwable instanceof RuntimeException) {
92-
throw (RuntimeException)throwable;
93-
} else if (throwable instanceof Error) {
94-
throw (Error)throwable;
91+
if (throwable instanceof RuntimeException runtimeEx) {
92+
throw runtimeEx;
93+
} else if (throwable instanceof Error er) {
94+
throw er;
9595
}
9696
}
9797

0 commit comments

Comments
 (0)