digitalmars.D - Request: add message parameter to assert()
- Sean Kelly (15/15) Jun 08 2005 The old horse still has a bit of life in it!
- Matthew (2/18) Jun 10 2005
- Unknown W. Brackets (4/32) Jun 11 2005 If I do so recall, I posted about why I still think this is necessary,
- Ben Hinkle (24/43) Jun 13 2005 Once Exceptions get stack trace abilities the file/lineno will be less
The old horse still has a bit of life in it! If we can assume that the current assert expression to evaluate as: Is there any chance this could be changed to: Since the default behavior of assert in D is to throw an exception, it seems quite reasonable that the programmer be given a means to supply the message that exception carries. For DMD, this would change: to: I'd do this myself except assert is treated as a keyword in D, and it seems unreasonable to ask users to call a different function if they want to supply a message. Sean
Jun 08 2005
gets my vote "Sean Kelly" <sean f4.ca> wrote in message news:d87tsv$2sd9$1 digitaldaemon.com...The old horse still has a bit of life in it! If we can assume that the current assert expression to evaluate as: Is there any chance this could be changed to: Since the default behavior of assert in D is to throw an exception, it seems quite reasonable that the programmer be given a means to supply the message that exception carries. For DMD, this would change: to: I'd do this myself except assert is treated as a keyword in D, and it seems unreasonable to ask users to call a different function if they want to supply a message. Sean
Jun 10 2005
If I do so recall, I posted about why I still think this is necessary, despite the response that file and line numbers should be enough for developers (an argument that obviously ignored open source software.) -[Unknown]The old horse still has a bit of life in it! If we can assume that the current assert expression to evaluate as: Is there any chance this could be changed to: Since the default behavior of assert in D is to throw an exception, it seems quite reasonable that the programmer be given a means to supply the message that exception carries. For DMD, this would change: to: I'd do this myself except assert is treated as a keyword in D, and it seems unreasonable to ask users to call a different function if they want to supply a message. Sean
Jun 11 2005
"Sean Kelly" <sean f4.ca> wrote in message news:d87tsv$2sd9$1 digitaldaemon.com...The old horse still has a bit of life in it! If we can assume that the current assert expression to evaluate as: Is there any chance this could be changed to: Since the default behavior of assert in D is to throw an exception, it seems quite reasonable that the programmer be given a means to supply the message that exception carries. For DMD, this would change: to: I'd do this myself except assert is treated as a keyword in D, and it seems unreasonable to ask users to call a different function if they want to supply a message. SeanOnce Exceptions get stack trace abilities the file/lineno will be less crucial (though the linno will still let you tell which assert in a given function failed). If one doesn't mind writing a bit more for message asserts here's a simple solution private import std.format; void assertStr(int val,...) { char[] s; void putc(dchar c){ std.utf.encode(s, c); } if (!val) { // I would call std.string.sformat but it takes ... so // I can't :-( Someone should add va_list versions. std.format.doFormat(&putc, _arguments, _argptr); throw new Exception(s); } } int main() { int a,b; a = 10; version(Assert) assertStr(a == b, "oops, b was %d",b); version(Assert) assertStr(a == b, "%s(%d) another",__FILE__,__LINE__); return 0; }
Jun 13 2005