<span id="Label3"></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(180,38,26)"><span style="color:#000000">It is normal to encounter program crashes in iOS development, how to catch exception information when a program crashes and notify the developer, which is the method chosen by most Software. Here's How to do this in ios:<br><br>1. Add an exception capture listener during program startup to handle callback actions when the program crashes<br><wbr><wbr></wbr>Nssetuncaughtexceptionha<wbr><wbr></wbr>Ndler (&uncaughtexceptionhandler<wbr><wbr></wbr>);<br><wbr><wbr></wbr>Official document Description: sets the top-level error-handlingfunction where you can perform last-minute logging before Theprogram Terminates.<br><wbr><wbr></wbr>Uncaughtexceptionhandler<wbr><wbr></wbr>is a function pointer, This function needs us to implement, can take the name that we Want. When a program crashes abnormally, the function is called, which is the same concept as the callback function in c,c++.<br><br><br>2. Implement your own processing functions<br>void Uncaughtexceptionhandler<wbr><wbr></wbr>(nsexception *exception) {<br><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsarray *arr= [exception callstacksymbols];//get current Call stack information<br><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsstring*reason = [exception reason];//is very important, is the cause of the crash<br><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsstring*name = [exception name];//exception type<br><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><br><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>NSLog (@ "exception type:%@ \ crash reason:%@ \ n Call stack info:%@", name, reason, arr);<br>}<br><br>The above code is very simple, but the effect is very large.<br><br>Get to the day of the crash, how to send to the developer, now generally persist the crash information locally, the next time the program starts, The crash information as a log sent to the Developer.</span></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(180,38,26)"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(180,38,26)"><span style="color:#000000"> </span> <span style="color:#3495af">nsstring</span> <span style="color:#000000"> * StrM = [</span><span style="color:#3495af">nsstring</span><span style="color:#000000"></span><span style="color:#3495af">stringwithformat</span><span style="color:#000000">:</span>@ " MyException type:%@ \ Crash reason:%@ \ Call Stack info:%@ "<span style="color:#000000">, name, reason, arr];</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(52,149,175)"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(52,149,175)"><span style="color:#000000">[[</span>nsuserdefaults<span style="color:#000000"></span>standarduserdefaults<span style="color:#000000">] </span>setobject<span style="color:#000000">: StrM</span>forkey<span style="color:#000000">:</span><span style="color:#b4261a">@ " EXCEPTION "</span><span style="color:#000000">];</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(52,149,175)"><p style="margin-top:0px; margin-bottom:0px; font-size:11px; font-family:Menlo; color:rgb(52,149,175)"><span style="color:#000000">[[</span>nsuserdefaults<span style="color:#000000"></span>standarduserdefaults<span style="color:#000000">]</span>synchronize<span style="color:#000000">];</span></p></p><p><p>Capture program crash log in IOS</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service