annoying problem (maybe actually solved with jvm's...
# codereview
g
annoying problem (maybe actually solved with jvm's loosening of constructor rules in valhalla?): I want to create an exception instance. I already have its stack trace as a variable, so I want to create this exception, and then set its stack trace. I want to create a custom exception type for this purpose. What is the most idiomatic way to do this?
Copy code
class MyCustomException(val trace: List<StackTraceElement>): Exception(){
    init {
        stackTrace = trace.toTypedArray()
    }

    override fun fillInStackTrace() = this //interrupt call to dump back-trace into stack-trace
}
?
g
which simply lets the jvm spend the time of dumping the backtrace to the stack trace?
seems inelegant, I would think that with the stack trace in hand I could implement
fillInStackTrace
myself
j
true, not very elegant
h
But does it matter? Shouldn't exceptions be … you know … exceptional? So rare, that their performance never is an issue?