Native: add KotlinThrowable.asError() to the generated Obj-C framework
This method can be useful when overriding a throwing Kotlin method in Swift or Obj-C. In this case, a user can call asError to wrap Kotlin exception to (NS)Error and then throw it to Kotlin, which will unwrap it back. ^KT-45127 Fixed
This commit is contained in:
committed by
Space
parent
c988ecf59b
commit
d531df1643
@@ -6,4 +6,5 @@
|
||||
#import "Types.h"
|
||||
|
||||
extern "C" id Kotlin_ObjCExport_ExceptionAsNSError(KRef exception, const TypeInfo** types);
|
||||
extern "C" id Kotlin_ObjCExport_WrapExceptionToNSError(KRef exception);
|
||||
extern "C" OBJ_GETTER(Kotlin_ObjCExport_NSErrorAsException, id error);
|
||||
|
||||
@@ -70,6 +70,10 @@ extern "C" id Kotlin_ObjCExport_ExceptionAsNSError(KRef exception, const TypeInf
|
||||
TerminateWithUnhandledException(exception);
|
||||
}
|
||||
|
||||
return Kotlin_ObjCExport_WrapExceptionToNSError(exception);
|
||||
}
|
||||
|
||||
extern "C" id Kotlin_ObjCExport_WrapExceptionToNSError(KRef exception) {
|
||||
NSMutableDictionary<NSErrorUserInfoKey, id>* userInfo = [[NSMutableDictionary new] autorelease];
|
||||
userInfo[@"KotlinException"] = Kotlin_ObjCExport_refToObjC(exception);
|
||||
userInfo[@"KotlinExceptionOrigin"] = @(&kotlinExceptionOriginChar); // Support for different Kotlin runtimes loaded.
|
||||
|
||||
Reference in New Issue
Block a user