Hello guys, I created a custom exception in Kotlin...
# kotlin-native
j
Hello guys, I created a custom exception in Kotlin Native and I was able to capture the exception in the iOS platform but I’m not able to access the custom properties of my exception. Is there any way to do that? Native Custom Exception:
Copy code
class MyException(
    val myCustomProp: Boolean
): Throwable()
in iOS with Swift:
Copy code
} catch let error as MyException {
      print("custom value: \(error.myCustomProp)")
} catch let error {
      print(error.localizedDescription)
}
but it always go to the latest catch
d
I'm not too familiar with swift but can you print out the class name of the exception caught in the last catch?
j
sure let me try, not so familiar too lol
I think it’s an NSError but let me check
I printed
error
and it said:
Copy code
Error Domain=KotlinException Code=0 "Empty Body but it's ok." UserInfo={NSLocalizedDescription=Empty Body but it's ok., KotlinException=booking.api.BookingApiClientException: Empty Body but it's ok., KotlinExceptionOrigin=}
I tried KotlinException but doesn’t exists. Also I found there is a KotlinThrowable but it’s not catch neither
this error msg is what I set in the custom exception so at least the msg is there and also the type appears there but not sure how to extract it
OH I got it!!! it was at the end an NSError:
Copy code
} catch let error as NSError {
            let ke = error.kotlinException as! BookingApiClientException
            print("Expected error is: \(ke.isExpectedError) ")
        }
d
👍🏼
j
Thanks man !!