okay I seee : ```fun NonFatal(t: Throwable): Boole...
# arrow
s
okay I seee :
Copy code
fun NonFatal(t: Throwable): Boolean =
  when (t) {
    is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> false
    else -> true
  }
r
In general you should avoid capturing Throwables listed there because you have no guarantees the VM is in a state that you can do anything about it
so those should propagate upstream most likely toward a crash in most cases
👍 1
s
Okay. Was just curious as I got raiseNonFatal in the dropdown list in IntelliJ.
r
yes, if you are gonna raise a Throwable that you don’t know what kind it is the safe path is NonFatal
also that is gonna change because instantiating a Throwable itself is an effect
it call into fillInStackTrace which is a native slow op to gather the stack frames info
which means that anything related to throwable moves to Arrow Fx and just suspend
s
okay. Do you think this approach would still cahh
fillInStackTrace
:
Copy code
sealed class DomainError : Throwable() {
    object AuthenticationTokenInvalid : DomainError()
    object AuthenticationTokenUnavailable : DomainError()
    object DatabaseFatalError : DomainError()
    object NotFound : DomainError()
}
and then for example :
Copy code
myIO.handleErrorWith { e ->
    when (e) {
        is ClientRequestException -> DatabaseFatalError.raiseError()
        else -> NotFound.raiseError()
    }
}
You gave me once a link to a bolg post about
fillInStackTrace
, so did a little reading. What I understood was, if I can use static exceptions, then it can get away without doing this expensive op. But I am not sure.
r
you need to override fillInStackTrace in DomainError and return yourself
it’s what the Throwable constructor calls
s
nice, Thanks 🙂
👍 1