Skip to content

Commit

Permalink
Improve exception handling tooling.
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineThreepwood committed Feb 27, 2024
1 parent 69be6a7 commit 57f9689
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,17 @@ val Throwable.causedBySystemShutdown get() = ExceptionProcessor.isCausedBySystem
val Throwable.causedByInterruption get() = ExceptionProcessor.isCausedByInterruption(this)
fun Throwable.setInitialCause(initialCause: Throwable?) =
ExceptionProcessor.setInitialCause(this, initialCause)

fun <O> tryOrNull(block: () -> O): O? =
try {
block()
} catch (e: NotAvailableException) {
null
}

fun <I, O> I.tryOrNull(block: (I) -> O): O? =
try {
block(this)
} catch (e: NotAvailableException) {
null
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand Down Expand Up @@ -77,10 +77,18 @@ public FatalImplementationErrorException(final Object source, final Throwable ca
StackTracePrinter.detectDeadLocksAndPrintStackTraces(logger);
}

/**
* Default constructor that can be used to restore a fatal implementation error from a serialized state.
*/
public FatalImplementationErrorException(final String message, final Throwable cause) {
super(message, cause);
}

/**
* Method detects the class of the given instance. In case the instance itself is the class these one is directly returned.
*
* @param object
*
* @return
*/
private Class detectClass(final Object object) {
Expand Down

0 comments on commit 57f9689

Please sign in to comment.