Why is raising an NSException not bringing down my application?

后端 未结 6 680
难免孤独
难免孤独 2020-12-30 08:23

The Problem

I\'m writing a Cocoa application and I want to raise exceptions that will crash the application noisily.

I have the following li

6条回答
  •  囚心锁ツ
    2020-12-30 09:18

    I've posted this question and answer as I wish someone had told me this, oh, about a year ago:

    Exceptions thrown on the main thread are caught by NSApplication.

    I skim read the docs on NSException end to end, with no mention of this that I can recall. The only reason I know this is because of the fantastic Cocoa Dev:

    http://www.cocoadev.com/index.pl?ExceptionHandling

    The Solution. I guess.

    I've got a daemon with no UI that almost entirely runs on the main thread. I'll have to transfer the whole app to run background threads, unless someone else can suggest a way of stopping NSApplication catching just the exceptions I throw. I'm pretty sure that's not possible.

提交回复
热议问题