Skip to content

Create a rethrow function to properly handle non-recoverable Throwables #5865

Description

@runningcode

Related to #5513, we want to create a function/lambda so that we can catch Throwable and safely rethrow errors that we shouldn't catch.

The types of exceptions and errors that should be rethrown should be OOMs, ProcessDeath, Stackoverflow, InterruptedException and other types of errors (research this).

Example

fun rethrowFatal(t: Throwable) {
  if (t is X) {
     throw t
  } else if (t is Y) {
     throw t
  }
  // just ignore or log?
}

so it can be used like:

try {
  doDangerousThing()
} catch(t: Throwable) {
  rethrowFatal(t)
}


Ideally we shouldn't use this function often, just when we really don't want to crash.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions