我收到的代码= 1或代码= 2表示EXC_BAD_ACCESS错误。我想知道code = 1和code = 2之间有什么区别?
答案 0 :(得分:28)
Code = 1是KERN_INVALID_ADDRESS,code = 2是KERN_PROTECTION_FAILURE。两者都是 在"Technical Note TN2123 CrashReporter"中解释:
最常见的例外形式是:
- EXC_BAD_ACCESS / KERN_INVALID_ADDRESS - 这是由线程引起的 访问未映射的内存。它可以由数据访问触发 或取指令;线程状态部分描述了如何操作 说出不同之处。
- EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE - 这是 由线程试图写入只读内存引起的。这是 总是由数据访问引起的。
代码在<mach/kern_return.h>
中定义:
#define KERN_INVALID_ADDRESS 1
/* Specified address is not currently valid.
*/
#define KERN_PROTECTION_FAILURE 2
/* Specified memory is valid, but does not permit the
* required forms of access.
*/
并在<mach/exception_types.h>
中记录了代码
对于EXC_BAD_ACCESS是kern_return_t
:
#define EXC_BAD_ACCESS 1 /* Could not access memory */
/* Code contains kern_return_t describing error. */
/* Subcode contains bad memory address. */