Is there any workaround to avoid `@Throws` annotat...
# kotlin-native
k
Is there any workaround to avoid
@Throws
annotation and handle the error on the native platform side. For example I have function in kotlin native that can throw
SocketTimeoutException
, Is there anyway to handle it on the iOS side without adding the
@Throws
annotation on my function?
m
Convert to using return types like
Result
instead of throwing an exception.
k
yeah that seems like an option. But feels weird to catch all the exceptions the function can potentially throw and wrap it to a return type. @mkrussel anychance you have used
unhandledExceptionHook
before? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native/set-unhandled-exception-hook.html
m
No. Right now I only use exceptions for programmers bugs and don't handle them. Anything that is expected like IOExceptions, I catch at the point of the IO and convert to result type objects. I feel this is safer, since Kotlin doesn't have checked exceptions. There also aren't that many places where I would have used checked exceptions (pretty much just IO work).
k
gotcha. That makes sense. Thank you for the prompt replies, appreciate it.