简体   繁体   English

objective-c中的例外情况

[英]Exception in objective-c

I'm a .NET Developer and I'm creating an API for logging exceptions. 我是.NET开发人员,我正在创建用于记录异常的API。

Now I'm creating one for objective-c. 现在我正在为objective-c创建一个。

My question is: what data are found in the exception in objective-c? 我的问题是:在objective-c中的异常中找到了哪些数据?

In .NET we have stacktrace , message...etc what are the ones in objective-c? 在.NET中,我们有stacktrace,message ...等Objective-c中的那些是什么?

Thanks in advance. 提前致谢。

edit: 编辑:

Please note that I know in objective-c there is try catch block. 请注意,我知道在objective-c中有try catch块。 This isn't what I'm asking for. 这不是我要求的。 the exception has data in it such as code(error code). 异常中包含数据,例如代码(错误代码)。 What else there? 还有什么?

Java for example have stack trace. 例如,Java具有堆栈跟踪。 .NET have stack trace and message. .NET具有堆栈跟踪和消息。

What are the one's in objective c? 目标c中的那个是什么?

Just check the NSException class reference for information about which properties and methods it supports. 只需检查NSException类引用,以获取有关它支持的属性和方法的信息。

Note however that catching exceptions is extremely uncommon in Objective-C, in particular, exceptions are never used for control flow, which is different from other languages/frameworks you may be used to. 但请注意,在Objective-C中捕获异常非常罕见,特别是异常从未用于控制流,这与您可能习惯的其他语言/框架不同。

Exceptions are mostly raised for programmer errors that should be fixed in your code instead of being caught at runtime. 程序员错误通常会引发异常,应该在代码中修复,而不是在运行时捕获。 Other types of errors are usually represented as an NSError . 其他类型的错误通常表示为NSError The Exception Programming Topics documentation has some more details about this. 异常编程主题文档有关于此的更多详细信息。

In the chapter Exceptions and the Cocoa Frameworks , it also notes that: Exceptions和Cocoa框架一章中,它还指出:

The Cocoa frameworks are generally not exception-safe. Cocoa框架通常不是例外安全的。 The general pattern is that exceptions are reserved for programmer error only, and the program catching such an exception should quit soon afterwards. 一般模式是异常仅为程序员错误保留,并且捕获此类异常的程序应该很快就会退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM