ios - 当点击 NSSetUncaughtExceptionHandler 时,使用 CoreGraphics 在屏幕上绘制

标签 ios objective-c exception core-graphics

当 NSSetUncaughtExceptionHandler 被调用时,我试图在屏幕上绘制一些简单的东西,但什么也没有发生。 有没有其他方法可以捕获异常并快速在屏幕上绘制内容?

NSSetUncaughtExceptionHandler(&exceptionHandler);

void exceptionHandler(NSException *exception)
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10.0, 10.0)];
    [path moveToPoint:CGPointMake(10.0, 10.0)];
    [path addLineToPoint:CGPointMake(10.0, 450.0)];
    [path addLineToPoint:CGPointMake(310.0, 450.0)];
    [path addLineToPoint:CGPointMake(310.0, 10.0)];
    [path addLineToPoint:CGPointMake(10.0, 10.0)];

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [path CGPath];
    shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
    shapeLayer.lineWidth = 3.0;
    shapeLayer.fillColor = [[UIColor clearColor] CGColor];

    [APP_DELEGATE_WINDOW.rootViewController.view.layer addSublayer:shapeLayer];
    [APP_DELEGATE_WINDOW makeKeyAndVisible];
}

最佳答案

我不确定 NSSetUncaughtExceptionHandler 是否是在屏幕上绘制内容的好地方。

Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.

大多数崩溃报告者都会仔细记录痕迹,并尽量不要“触摸”除此之外的任何东西。

如果你真的想画一些东西(什么?),你可能应该首先捕获一个特定的异常。只是没有任何未捕获的异常。

关于ios - 当点击 NSSetUncaughtExceptionHandler 时,使用 CoreGraphics 在屏幕上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125728/

相关文章:

c - Lua设置默认错误处理程序

java.rmi.ServerException : RemoteException occurred in server thread (ClassNotFoundException)

java - java中捕获异常?

在 Swift iOS 中解码 PHP JSON 返回空值

ios - 字符串比较不适用于 Swift

ios - 如何以编程方式成功执行从 SKScene 到 UIViewController 的转场

objective-c - 访问屏幕上所有应用程序窗口的 NSWindow.level

ios - 在哪里可以找到 Parse 保存的数据?

ios - 添加具有行动画的单元格时,将 tableview 保持在相同的滚动位置

iphone - 如何使用 iOS 接收单击并按住远程控制事件?