[Tutor] How to raise error without the stack trace

Steven D'Aprano steve at pearwood.info
Tue Nov 29 13:38:04 CET 2011


Karim wrote:

> I did not explain myself clearly. I Kow when I fired it because it is in 
> code like:
> 
> If not value:
>     raise MyError('You did wrong here!')
> 
> And in that case I did not want the stack trace because I know perfectly 
> where the message is triggered.

Really?

You must have amazingly tiny programs that are incredibly bug free then. I'm 
jealous :-)

In my programs, if I get MyError('You did wrong here!'), I need all the help I 
can get to find out what sort of wrong it was, why value is incorrect, what 
function called it, and where the value came from originally. The stack trace 
is often very helpful for that: the variable might get the wrong value half a 
dozen function calls away from where the exception happens.

Sometimes the error is obvious, and the stack trace is easy to ignore. It's 
the cases that aren't obvious that you should care about.

If you think Python stack traces are annoying, you haven't seen anything. 
Once, I saw a SAP application unexpected crash, and it printed (I am not 
exaggerating, or joking) half a ream of printouts. Seriously. The stack of 
printouts was two centimetres thick.

We called the supplier and asked if they wanted the printouts for debugging, 
and they said no.




-- 
Steven


More information about the Tutor mailing list