-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔇 silent changes: add reflection4j and traverse4j #3
- Loading branch information
1 parent
e2deaa8
commit 18fe1e2
Showing
4 changed files
with
948 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
plugin/src/main/groovy/org/unify4j/common/Exception4j.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.unify4j.common; | ||
|
||
public final class Exception4j { | ||
|
||
/** | ||
* Safely ignores a given Throwable or rethrows it if it is an error that should not be ignored. | ||
* Specifically, it checks for {@link OutOfMemoryError} and rethrows it, as it should not be suppressed. | ||
* Other types of {@link Throwable} are ignored. | ||
* | ||
* @param t The {@link Throwable} to possibly ignore. If it is an instance of {@link OutOfMemoryError}, it is rethrown. | ||
*/ | ||
public static void safelyIgnoreException(Throwable t) { | ||
if (t instanceof OutOfMemoryError) { | ||
throw (OutOfMemoryError) t; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the deepest (most nested) cause of a given {@link Throwable}. | ||
* This method iteratively traverses the exception chain via {@link Throwable#getCause()} | ||
* to find and return the root cause of the exception. | ||
* | ||
* @param e The {@link Throwable} whose deepest cause is to be found. | ||
* @return The deepest (root) cause {@link Throwable}. | ||
*/ | ||
public static Throwable getDeepestException(Throwable e) { | ||
while (e.getCause() != null) { | ||
e = e.getCause(); | ||
} | ||
return e; | ||
} | ||
} |
Oops, something went wrong.