Hi, are the iOS exception working in same way as r...
# multiplatform
j
Hi, are the iOS exception working in same way as regular jvm/kt one ? I have a code which is throwing a
NSInvalidArgumentException
, but having a test with the call in try/catch statement doesn't catch it 🤔
Copy code
val controller = UIImagePickerController()
runCatching {
     controller.setSourceType(UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera)
}
basically having this code, and the test still failing due to
Copy code
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000018048d8a8 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x000000018008409c objc_exception_throw + 56
	2   UIKitCore                           0x0000000184adebcc -[UIImagePickerController sourceType] + 0
....
j
Hi @Pamela Hill thank you for response. I'm not sure that link helps... based on this https://kotlinlang.slack.com/archives/C3PQML5NU/p1708634741339569 there is a
extraOpts = listOf("-Xforeign-exception-mode", "objc-wrap")
but I'm not sure how to apply it for "project" in general... the exception is not from 3rd party (cocoalib) dependency
p
Basically, the article says to add @Throws to your functions that possibly could throw this exception if it's a Kotlin exception. Exceptions are like errors in Swift, you can't recover from them and causes a program termination. So the exception/error concept is flipped in Kotlin/Swift.