Why is `String.toInt()` just an alias for `parseIn...
# stdlib
d
Why is
String.toInt()
just an alias for
parseInt()
, but
String.toIntOrNull()
is custom implementation instead of trycatch implementation of parseInt()? Is it because throwing exceptions in java is heavy or something like that?
g
Yes, this is because of a Throwable that will be created but ignored
👌 1
r
To extend a bit on that, every time* a Throwable is created, it captures the current stack trace, which is pretty costly, and throwing and catching across function boundaries also has some overhead. *actually not every time, see this stackoverflow answer: https://stackoverflow.com/a/36344265/3887813