Error Message useless

janderson askme at me.com
Sat May 10 16:58:41 PDT 2008


Nick Sabalausky wrote:
<snip>
> If you're not familiar with the trick of debugging output statements, it's 
> like this: Start with main() and sprinkle normal output statements through 
> it. For instance, if your main() is like this:
> 
> void main()
> {
>    someFunc();
>    if(something)
>        doSomething();
>    anotherFunc();
>    yetAnotherFunc();
> }
> 
> Then do this:
> 
> void main()
> {
> Stdout("1").newline;
>    someFunc();
> Stdout("2").newline;
>    if(something)
>    {
> Stdout("3").newline;
>        doSomething();
> Stdout("4").newline;
>    }
> Stdout("5").newline;
>    anotherFunc();
> Stdout("6").newline;
>    yetAnotherFunc();
> Stdout("7").newline;
> }
> 
> Obviously, copy/paste helps there ;) Run that and you'll get something like:
> 
> 1
> 2
> 5
> tango.core.Exception.IllegalArgumentException: Argument not valid
> 
> In this case, we know the if() ended up false and "doSomething()" was 
> skipped, and we also know the exception was thrown somewhere in 
> "anotherFunc()". So rip those "Stdout's" out of there, and do the same thing 
> in "anotherFunc()". Keep drilling down like that until you find the problem.
> 
> I do that all the time in my own code (because so far I've been too lazy to 
> actually get a debugger set up with D :) ).
> 
> 

Here's a tip:

Use: __FILE__, __LINE__ in your arguments.  That way you don't need to 
keep changing the value.

I bet one could write a mixin that would do this automatically and you'd 
simply wrap each function in that mixin.

-Joel



More information about the Digitalmars-d mailing list