Is there a way to add or edit the message thrown by assert? I’d like to use something like
assert(a == b, "A must be equal to B");
Then, the compiler adds line, time and so on…
Is it possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A hack I’ve seen around is to use the
&&operator. Since a pointer “is true” if it’s non-null, you can do the following without altering the condition:Since
assertshows the condition that failed, it will display your message too. If it’s not enough, you can write your ownmyAssertfunction or macro that will display whatever you want.