"Go" Using assertion Nsassert () debugger Error

Source: Internet
Author: User

Nsassert () is just a macro that is used for bugs in the development phase of the debugger, by passing conditional expressions for Nsassert () to determine if a bug is true, to satisfy a conditional return truth, to run a program, to throw an exception if a false value is returned, and to customize the description of the exception. Nsassert () is defined in this way:

#define NSASSERT (condition, desc)

condition is a conditional expression, with a value of Yes or No;desc as an exception, usually nsstring. When the program continues to run when Conditon is yes, exception information with desc description is thrown when no. Nsassert () can appear at any location in the program. Specific examples are as follows:

When generating an Lotteryentry object, the incoming nsdate cannot be determined by nil, adding Nsassert (). Object initialization source code is as follows:


-(ID) initwithentrydate: (nsdate *) thedate{

Self =[super init];

if (self) {

Nsassert(thedate!= nil, @ "Argument must benon-nil");

entrydate =thedate;

Firstnumber = (int)random ()% + 1;

Secondnumber = (int)random ()% + 1;

}

return self;

}

Next, when you build the object, pass in a nsdate with a value of nil to see if the assertion is running.

Lotteryentry *nilentry =[[lotteryentry alloc] initwithentrydate:nil];

The assertion effect is as follows:


2013-01-17 20:49:12.486 lottery[3951:303] * * * terminating appdue to uncaught exception ' Nsinternalinconsistencyexception ', Reason: ' Argument must be Non-nil '

First throw Call stack:

(

0 corefoundation 0x00007fff90c590a6 __exceptionpreprocess +198

1 LIBOBJC. A.dylib 0x00007fff8fd2a3f0 Objc_exception_throw + 43

2 corefoundation 0x00007fff90c58ee8 +[nsexceptionraise:format:arguments:] + 104

3 Foundation 0x00007fff88dae6a2-[nsassertionhandlerhandlefailureinmethod:object:file:linenumber:des Cription:] +189

4 lottery 0x0000000100001929-[lotteryentryinitwithentrydate:] + 249

5 Lottery 0x0000000100001794 main + 932

6 libdyld.dylib 0x00007fff8d83f7e1 start + 0

)

Libc++abi.dylib:terminate called throwing an exception

"Go" Using assertion Nsassert () debugger Error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.