<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">To be very clear, i’m concerned about iOS not mac os x. I pulled up a crash report using xcode tools, and saw no mention of the string output by fatal error. If there is someway after the fact of, on an iPhone or iOS interogating the asl_log when you restart your program to glean the error message, i’m all ears.<div class=""><br class=""></div><div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Jun 26, 2017, at 10:01 AM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 23, 2017, at 9:13 PM, David Baraff via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I realize this is slightly centric to iOS, but it irks me that both Apple’s crash report logs and popular platforms like PLCrashReporter can do the hard stuff like give you a stack trace, but are *completely* unable to display the error message from terminating a program via fatalError(), or the error message from, e.g. dying with a bad optional.<br class=""><br class="">Is there *any* to intercept the error messages that from fatalError() and similar like things in swift (bad optionals, invalid array accesses, assertions)? I would think that some sort of a “hook” into these standard error routines would be a good thing.<br class=""><br class="">In my case, if I could simply save that darn error string in a file, i could pick it up when the app next launches and report it along with the rest of the info like the stack/signal, etc.<br class=""><br class="">I’ve been looking through the code in stdlib/public/runtime/Errors.cpp but haven’t found anything promising that lets me jump in there. In my code, I’m likely to write things like<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>guard let x = … else {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>fatalError(“Data type has payload <T> but is hooked to UI control with intrinsic type <U>”)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">and having that exact string tells me precisely what’s going, far simpler than a stack trace.<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">Fatal error messages already get logged three ways:</div><div class=""><br class=""></div><div class="">- Printed to the process's stderr;</div><div class="">- Logged to the system log using asl_log;</div><div class="">- Set as the crash reason for CrashReporter.</div><div class=""><br class=""></div><div class="">The crash messages should thus already be in your crash reports somewhere. See <a href="https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L168" class="">https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L168</a> and <a href="https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L204" class="">https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L204</a> for the relevant runtime source code. cc'ing Greg Parker who probably knows better exactly where these messages end up.</div><div class=""><br class=""></div><div class="">-Joe</div></div></div></blockquote></div><br class=""></div></div></body></html>