Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Imagination Technologies's MIPS group, in the past of other companies such as Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Thursday, March 08, 2012

Good programmers generate good error messages

On the list of my favorite things - NOT:

Programs that respond to user input errors with crashes and stack dumps.  Whether the stackdump is machine code, Perl, Python or whatever...

I could say something like "Good programmers write code that runs with legal input.  Better programmers write code that gives good error messages and/or otherwise handles illegal input better."

Except that it is as that programmers have to write so much error handling code.  Error handling code can grow to take up more space than the real code.

I like language systems that make it easier to write error handling code.  Not necessarily user friendly error messages, but error messages that give the user more of a chance tio figure out what went wrong.

this is one thing I like about C++ exceptions: throw a string-like error message.  When caught, add more info to the string, and throw again, until you get to the outpmost level whedre you die - oer some intermediate level where you can die or otherwise handle.

But I can here the dweebies say "You aren't supposed to throw string or char* exceptions".  True - in an "out-of-memory exception.  But except for that, concatenating or stacking string exception error messages are some of the simplest and best ways to report errors.  So make the exception system handle it.

Similarly, this sounds just like a stack dump.  But it is a user intelligible stack dump - some thought can go in to the strings that get thrown.

No comments: