Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 17, 2004 why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
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 :-[ |
March 17, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | 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 |
March 17, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | 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 number was > thrown, otherwise i have to track through my large project looking for the particular assert that threw up on me :-[ > > |
March 17, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | 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
|
March 17, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 > 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"); :) |
March 17, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote: > 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; > } > } > > 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. Miller |
March 18, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 > |
March 18, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juan C | "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 be able to > easily 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... > > > >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 > > > > |
March 18, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | 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. |
March 18, 2004 Re: why is assert() so useless? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | 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. |
Copyright © 1999-2021 by the D Language Foundation