www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Assert question

reply DLearner <abc.efg qwe.ert> writes:
Suppose a program contains several points that control should not 
get to.
So each such point is blocked by assert(0).
What is the recommended way of identifying which assert has been 
triggered?

Is one allowed anything like 'assert(0,"Crashed at point A");', 
where the message goes to stderr?
Jul 26 2016
next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/26/16 8:13 AM, DLearner wrote:
 Suppose a program contains several points that control should not get to.
 So each such point is blocked by assert(0).
 What is the recommended way of identifying which assert has been triggered?

 Is one allowed anything like 'assert(0,"Crashed at point A");', where
 the message goes to stderr?
In non-release mode, assert(0, msg) prints the message (an error is thrown). In release mode, the assert(0) halts the program immediately and does not print any message. So yes and no :) -Steve
Jul 26 2016
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 26 July 2016 at 12:13:02 UTC, DLearner wrote:
 What is the recommended way of identifying which assert has 
 been triggered?
If you compile with -g, run the program in a debugger. It will tell you. If you compile and do NOT use -release, the error message automatically printed by the assert will tell you the line number on the first line of output.
Jul 26 2016