opDispatch, duck typing, and error messages

Jonathan M Davis jmdavisProg at gmx.com
Thu Apr 21 16:33:45 PDT 2011


> bearophile wrote:
> > Maybe exceptions nature should be changed a little so they store
> > 
> > __FILE__ and __LINE__ on default (exceptions without this
> > information are kept on request, for optimization purposes).
> 
> I'd like that. Even with a stack trace, it's nice to have that
> available right at the top.
> 
> A while ago, someone posted a stack tracer printer for Linux to
> the newsgroup. Using that, this program:
> 
> void main() {
> throw new Exception("test");
> }
> 
> dmd test60 -debug -g backtrace.d
> 
> Prints:
> 
> object.Exception: test
> ----------------
> ./test60(_Dmain+0x30) [0x807a5e8]
> ./test60(extern (C) int rt.dmain2.main(int, char**) . void runMain()+0x1a)
> [0x807d566] ./test60(extern (C) int rt.dmain2.main(int, char**) . void
> tryExec(void delegate())+0x24) [0x807d4c0]
> ./test60(extern (C) int rt.dmain2.main(int, char**) . void runAll()+0x32)
> [0x807d5aa] ./test60(extern (C) int rt.dmain2.main(int, char**) . void
> tryExec(void delegate())+0x24) [0x807d4c0]
> ./test60(main+0x96) [0x807d466]
> /lib/libc.so.6(__libc_start_main+0xe6) [0xf75a5b86]
> ./test60() [0x807a4e1]
> 
> 
> 
> No line or file info! I'd really like to have something there.
> Though, actually, whether it's in the message or in the stack
> trace doesn't really matter. As long as it's there somewhere.
> 
> Most my custom exceptions use default params in their constructor
> to add it. Perhaps the base Exception should too?

I just checked. Exception _does_ take a default file and line number. So, 
anything derived from Exception doesn't have a file and line number, something 
is amiss.

- Jonathan M Davis


More information about the Digitalmars-d mailing list