update ErrorHandling.scala

This commit is contained in:
kenji yoshida 2024-09-11 07:36:03 +09:00 committed by GitHub
parent 8ead89691f
commit ee38417aff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 3 deletions

View File

@ -23,9 +23,16 @@ object ErrorHandling {
try { try {
Right(f) Right(f)
} catch { } catch {
case ex @ (_: Exception | _: StackOverflowError) => Left(ex) case ex @ (_: Exception | _: StackOverflowError) =>
case err @ (_: ThreadDeath | _: VirtualMachineError) => throw err Left(ex)
case x: Throwable => Left(x) case err: VirtualMachineError =>
throw err
case err if err.getClass.getName == "java.lang.ThreadDeath" =>
// ThreadDeath is deprecated
// https://bugs.openjdk.org/browse/JDK-8289610
throw err
case x: Throwable =>
Left(x)
} }
def convert[T](f: => T): Either[Exception, T] = def convert[T](f: => T): Either[Exception, T] =