I've been using Objective C on iOS for about a month but have a lot of prior C++ experience.
My understanding of EXC_BAD_ACCESS
is that it's essentially a Segmentation Fault, i.e. an attempt to access memory outside of allowed region. Though oddly enough I've also seen SIGSEGV
specifically somewhere in a crashing iOS app. I notice that there is a code parameter (e.g. code=1
) as part of this exception and I'm wondering what that code specifically means.
I've poked around google and can't seem to find formal documentation on this error, and apparently I'm not alone. Does anyone know what the code parameter here means?
What does EXC_BAD_ACCESS mean? EXC_BAD_ACCESS is an exception raised as a result of accessing bad memory. We're constantly working with pointers to memory in Swift that link to a specific memory address. An application will crash whenever we try to access a pointer that is invalid or no longer exists.
Code Block. Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000. This indicates that your app crash because it tried to referenced NULL. Code Block.
If you look at the crash log that's generated on your device, you'll see:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at <some address>
For further description of the code
parameter associated with an exception, you can refer to usr/include/mach/kern_return.h
. It provides moderately-readable constant names along with short comment blurbs associated with the constant values.
The fastest way to open that file is to type the constant KERN_INVALID_ADDRESS
into your Xcode file and choose "Jump to Definition". ;)
FYI: code=1
relates directly to KERN_INVALID_ADDRESS
. The comment blurb associated with this constant reads:
/* Specified address is not currently valid. */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With