app中发生异常,exc_bad_acess后,向指定邮箱发邮件报告的方法

本文介绍了如何在应用启动时设置信号处理器以捕获并处理SIGSEGV异常,并通过异常处理器收集异常信息并将其发送至指定邮箱。同时,实现了一个自定义的异常处理器来获取并发送异常详情。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
//exc_bad_acess
void mysighandler(int sig)
{
      void * backtraceFrames[128];
      int frameCount=backtrace(backtraceFrames,128);
     char **strs=backtrace_symbols(backtraceFrames,frameCount);
     NSString *str=[NSString stringWithFormat:@""];
     for(int i=0;i<frameCount;++i)
     {
           NSString *temp=[NSString stringWithUTF8String:strs[i];
           str=[str stringByAppendingString:temp];
     }
     //将str的内容发送到邮箱
   //......
}


//在applicationDidFinishLaunching中添加
signal(SIGSEGV,mysighandler);


 

//异常
void exceptionHandler(NSException * exception)
{
       //获取exception的属性,然后将详细信息发回指定邮箱
}
//在applicationDidFinishLaunching中添加
NSSetUncaughtExceptionHandler(&exceptionHandler);
 


 



                
mac终端打不开,提示信息如下:------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: Terminal [3804] Path: /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal Identifier: com.apple.Terminal Version: 2.14 (455) Build Info: Terminal-455000000000000~1602 Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2025-03-25 16:14:30.3736 +0800 OS Version: macOS 15.3.2 (24D81) Report Version: 12 Anonymous UUID: 5ED56A84-13F8-3F57-93F7-DC852E994061 Time Awake Since Boot: 6100 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000600084469b20 Exception Codes: 0x0000000000000001, 0x0000600084469b20 Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11 Terminating Process: exc handler [3804] VM Region Info: 0x600084469b20 is not in any region. Bytes after previous region: 1682119457 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL owned unmapped memory unmapped-unmapped [ 224K] rw-/rw- SM=PRV owned physical footprint (unmapped) ---> UNUSED SPACE AT END Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 Terminal 0x102f4fbf0 0x102f0c000 + 277488 1 Terminal 0x102f4fbc8 0x102f0c000 + 277448 2 Terminal 0x102f4e5a0 0x102f0c000 + 271776 3 AppKit 0x18e84af28 -[NSApplication(NSPersistentUIRestorationSupport) restoreWindowWithIdentifier:state:completionHandler:] + 368 4 AppKit 0x18e84a7c4 -[NSApplication(NSPersistentUIRestorationSupp
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值