D - why is assert() so useless?
- imr1984 (4/4) Mar 17 2004 the messages that assert throw are so undescriptive, that they are quite
- Vathix (29/35) Mar 17 2004 What I do is use my own Assert object that returns a useful string from
- Vathix (10/58) Mar 17 2004 Actually, you have to put this in there too:
- Matthew (4/8) Mar 17 2004 Agreed. This is something that requires attention soon.
- Ant (15/19) Mar 17 2004 ???
- imr1984 (7/26) Mar 17 2004 i mean that asserts dont descibe where they threw from, so you have to f...
- Juan C (4/23) Mar 17 2004 assert should not be built into the language, each developer should be a...
- Matthew (14/47) Mar 18 2004 able to
- J C Calvarese (9/16) Mar 18 2004 If you don't use it, then why do you care whether it's built into the
- Carlos Santander B. (9/13) Mar 18 2004 That's weird. Try this:
- imr1984 (2/18) Mar 18 2004
- Carlos Santander B. (5/19) Mar 18 2004 dmd inter
- Derek Parnell (15/39) Mar 18 2004 Confirmed.
- Walter (16/20) Mar 18 2004 was
- imr1984 (3/23) Mar 20 2004 well it doesnt for me :(
- C. Sauls (4/6) Mar 20 2004 Works for me, DMD 0.81 on WinXP(Home)...
- Andrew Edwards (17/19) Mar 20 2004 That's too bad...Maybe something wrong with the way you set up your syst...
the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[
Mar 17 2004
imr1984 wrote:the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[What I do is use my own Assert object that returns a useful string from toString() until the actual Assert does it. You should be able to just paste this into your source and start getting meaningful messages: class Assert : Object { private: char[] errstr; this(char[] filename, uint linnum) { errstr = "Assertion Failure " ~ filename ~ "(" ~ std.string.toString(linnum) ~ ")"; } public: /*************************************** * If nobody catches the Assert, this winds up * getting called by the startup code. */ void print() { puts(toString()); } char[] toString() { return errstr; } } -- Christopher E. Miller
Mar 17 2004
Vathix wrote:imr1984 wrote:Actually, you have to put this in there too: extern (C) static void _d_assert(char[] filename, uint line) { throw new Assert(filename, line); } so it finds your _d_assert() first and throws your Assert rather than the other. -- Christopher E. Millerthe messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[What I do is use my own Assert object that returns a useful string from toString() until the actual Assert does it. You should be able to just paste this into your source and start getting meaningful messages: class Assert : Object { private: char[] errstr; this(char[] filename, uint linnum) { errstr = "Assertion Failure " ~ filename ~ "(" ~ std.string.toString(linnum) ~ ")"; } public: /*************************************** * If nobody catches the Assert, this winds up * getting called by the startup code. */ void print() { puts(toString()); } char[] toString() { return errstr; } }
Mar 17 2004
Agreed. This is something that requires attention soon. "imr1984" <imr1984_member pathlink.com> wrote in message news:c39l55$1rgg$1 digitaldaemon.com...the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert numberwasthrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[
Mar 17 2004
On Wed, 17 Mar 2004 13:51:33 +0000, imr1984 wrote:the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[??? You mean the fatal errors. the assert actually does that (file and line) (dmd 0.81 linux) I started to do: try { ... } catch ( SomeError e ) { assert(0); } Ant
Mar 17 2004
In article <pan.2004.03.17.14.53.25.668012 yahoo.ca>, Ant says...On Wed, 17 Mar 2004 13:51:33 +0000, imr1984 wrote:i mean that asserts dont descibe where they threw from, so you have to find it out yourself, which almost defeats the point of them - it means you just have to do something like: throw new Error("there should be an assertion failure on line 13 but instead here is a lovely message instead"); :)the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[??? You mean the fatal errors. the assert actually does that (file and line) (dmd 0.81 linux) I started to do: try { ... } catch ( SomeError e ) { assert(0); } Ant
Mar 17 2004
assert should not be built into the language, each developer should be able to easily define own. On the other hand I never use assert anyway. In article <pan.2004.03.17.14.53.25.668012 yahoo.ca>, Ant says...On Wed, 17 Mar 2004 13:51:33 +0000, imr1984 wrote:the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[??? You mean the fatal errors. the assert actually does that (file and line) (dmd 0.81 linux) I started to do: try { ... } catch ( SomeError e ) { assert(0); } Ant
Mar 17 2004
"Juan C" <Juan_member pathlink.com> wrote in message news:c3b1sh$1ad7$1 digitaldaemon.com...assert should not be built into the language, each developer should beable toeasily define own. On the other hand I never use assert anyway.How do you use the DBC features if you don't use assert? Do you throw exceptions? Matthew P.S. If you don't use the DBC features, then I strongly recommend you wait for a while, go and rejig your code and fill it with ins, outs and invariants, and post a response saying something like "oh, exception for contracts, of course. ;) ". Otherwise, you've just scarred away most of your potential users. <g>In article <pan.2004.03.17.14.53.25.668012 yahoo.ca>, Ant says...quiteOn Wed, 17 Mar 2004 13:51:33 +0000, imr1984 wrote:the messages that assert throw are so undescriptive, that they arenumber wasuseless. I need them to tell me the file and line number the assertthethrown, otherwise i have to track through my large project looking forparticular assert that threw up on me :-[??? You mean the fatal errors. the assert actually does that (file and line) (dmd 0.81 linux) I started to do: try { ... } catch ( SomeError e ) { assert(0); } Ant
Mar 18 2004
Juan C wrote:assert should not be built into the language, each developer should be able to easily define own. On the other hand I never use assert anyway.If you don't use it, then why do you care whether it's built into the language or not? I think assert could be improved, but I'd like it to still be built into the language. (I do use assert though not as often as I should.)In article <pan.2004.03.17.14.53.25.668012 yahoo.ca>, Ant says...[...] -- Justin http://jcc_7.tripod.com/d/On Wed, 17 Mar 2004 13:51:33 +0000, imr1984 wrote:
Mar 18 2004
In article <c39l55$1rgg$1 digitaldaemon.com>, imr1984 says...the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[That's weird. Try this: interface A {} class B : A {} void foo (A a) { assert ( (cast(B) a) !== null ) ; } void main() { foo(new B); } Using DMD 0.81 on Win98 I get: "Error: AssertError Failure inter.d(3)". ------------------- Carlos Santander B.
Mar 18 2004
hmm strange, what was the command line for dmd? In article <c3cs9k$1brk$1 digitaldaemon.com>, Carlos Santander B. says...In article <c39l55$1rgg$1 digitaldaemon.com>, imr1984 says...the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert number was thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[That's weird. Try this: interface A {} class B : A {} void foo (A a) { assert ( (cast(B) a) !== null ) ; } void main() { foo(new B); } Using DMD 0.81 on Win98 I get: "Error: AssertError Failure inter.d(3)". ------------------- Carlos Santander B.
Mar 18 2004
In article <c3cub9$1fbg$1 digitaldaemon.com>, imr1984 says...hmm strange, what was the command line for dmd? In article <c3cs9k$1brk$1 digitaldaemon.com>, Carlos Santander B. says...dmd inter Where the contents of inter.d are those 4 lines above. ------------------- Carlos Santander B.That's weird. Try this: interface A {} class B : A {} void foo (A a) { assert ( (cast(B) a) !== null ) ; } void main() { foo(new B); } Using DMD 0.81 on Win98 I get: "Error: AssertError Failure inter.d(3)". ------------------- Carlos Santander B.
Mar 18 2004
On Thu, 18 Mar 2004 19:58:35 +0000 (UTC) (19/Mar/04 06:58:35 AM) , Carlos Santander B. <Carlos_member pathlink.com> wrote:In article <c3cub9$1fbg$1 digitaldaemon.com>, imr1984 says...Confirmed. C:\dparnell>type inter.d interface A {} class B : A {} void foo (A a) { assert ( (cast(B) a) !== null ) ; } void main() { foo(new B); } C:\dparnell>dmd inter.d C:\DPARNELL\DMD\BIN\..\..\dm\bin\link.exe inter,,,user32+kernel32/noi; C:\dparnell>inter Error: AssertError Failure inter.d(3) C:\dparnell> -- Derekhmm strange, what was the command line for dmd? In article <c3cs9k$1brk$1 digitaldaemon.com>, Carlos Santander B. says...dmd inter Where the contents of inter.d are those 4 lines above. ------------------- Carlos Santander B.That's weird. Try this: interface A {} class B : A {} void foo (A a) { assert ( (cast(B) a) !== null ) ; } void main() { foo(new B); } Using DMD 0.81 on Win98 I get: "Error: AssertError Failure inter.d(3)". ------------------- Carlos Santander B.
Mar 18 2004
"imr1984" <imr1984_member pathlink.com> wrote in message news:c39l55$1rgg$1 digitaldaemon.com...the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert numberwasthrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[It already does: ----------------------------------- C:\cbx\mars>type test.d void main() { assert(0); } C:\cbx\mars>dmd test \dm\bin\link test,,,user32+kernel32/noi; C:\cbx\mars>test Error: AssertError Failure test.d(4) C:\cbx\mars> ------------------------------------------
Mar 18 2004
well it doesnt for me :( Im using DMD 0.81 on XP In article <c3dgv8$2gfr$1 digitaldaemon.com>, Walter says..."imr1984" <imr1984_member pathlink.com> wrote in message news:c39l55$1rgg$1 digitaldaemon.com...the messages that assert throw are so undescriptive, that they are quite useless. I need them to tell me the file and line number the assert numberwasthrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[It already does: ----------------------------------- C:\cbx\mars>type test.d void main() { assert(0); } C:\cbx\mars>dmd test \dm\bin\link test,,,user32+kernel32/noi; C:\cbx\mars>test Error: AssertError Failure test.d(4) C:\cbx\mars> ------------------------------------------
Mar 20 2004
Works for me, DMD 0.81 on WinXP(Home)... -C. Sauls -Invironz imr1984 wrote:well it doesnt for me :( Im using DMD 0.81 on XP
Mar 20 2004
On Sat, 20 Mar 2004 12:52:22 +0000 (UTC), imr1984 <imr1984_member pathlink.com> wrote:well it doesnt for me :( Im using DMD 0.81 on XPThat's too bad...Maybe something wrong with the way you set up your system. I'm using DMD 0.81 on XP and it works just fine. F:\>ver Microsoft Windows XP [Version 5.1.2600] F:\>ren inpchar.d test.d F:\>type test.d void main() { assert(0); } F:\>dmd test F:\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi; F:\>test Error: AssertError Failure test.d(3) F:\>
Mar 20 2004