<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Jon,</div><div class=""><br class=""></div><div class="">I ran into a similar situation and needed a way to not only catch NSExceptions from Swift, but throw them as well. If it would he useful to you, it's part of the open-source CleanroomBridging module, which is intended to ease a few Swift/ObjC interoperability issues. The header file for the exception-related code is here:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/emaloney/CleanroomBridging/blob/master/Sources/Exception.h" class="">https://github.com/emaloney/CleanroomBridging/blob/master/Sources/Exception.h</a></div><div class=""><br class=""></div><div class="">It is included in the module's bridging header, so you can use it from Swift.</div><div class=""><br class=""></div><div class="">Evan</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 24, 2016, at 2:06 PM, Jon Brooks via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Apologies if this has come up before - I've fallen behind in following this list.<br class=""><br class=""></div>I recently ran into an issue where I needed to be able to catch NSExceptions raised by Objective C API in Swift, and found no good way to do that.&nbsp; Currently the only possible way is to via Objective C code that wraps the call in an Objective C style @try/@catch block.&nbsp; If building a swift framework, this means a separate module, since we can't use bridging headers.<br class=""><br class=""></div>My quick attempt at a workaround can be seen here: <a href="https://github.com/jonbrooks/ObjCTryCatch" class="">https://github.com/jonbrooks/ObjCTryCatch</a> and there are other workarounds out there too.&nbsp; I wondered if there has been any discussion to building something like this into swift directly.&nbsp; I don't really have any good ideas, but maybe something like<br class="">&nbsp;&nbsp;&nbsp; <br class=""></div>&nbsp;&nbsp;&nbsp; do {<br class=""></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objc_try someObjectiveCInstance.methodThatMightRaiseException()<br class=""></div>&nbsp;&nbsp;&nbsp; } catch {<br class=""></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //error would be an ErrorType that contains info about the exception raised, or the exception itself?<br class=""><div class="">&nbsp;&nbsp;&nbsp; }<br class=""><br class=""></div><div class="">Any thoughts?<br class=""><br class=""></div><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><br class=""><br class=""></div></div></div></div></div></div></div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>