[Tutor] exceptions

alan.gauld@bt.com alan.gauld@bt.com
Mon, 15 Apr 2002 10:22:58 +0100


------_=_NextPart_001_01C1E45F.222683A0
Content-type: text/plain; charset="ISO-8859-1"

>  How do you approach error trapping and use exceptions in Python to  
>  take care of it?  How do you for all the possible dumb user mistakes?   
 
My tutor contains a page on this subject, plus we just had a thread on it.
 
>  I mean give me the kind of thought process of how I should go about  
>  thinking this through in planning my program. 
 
The main thing is just to think through what could 
go wrong and catch those exceptions at the last point 
that you can sensibly deal with them.
 
For production code I routinely put a try:/except/ 
handler around my entire program which just says 
"Oops something unexpected happened". But thats just 
to shield the gentle users from unsightly stack traces. 
I comment it out during development/testing.
 
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld
<http://www.freenetpages.co.uk/hp/alan.gauld>  

 


------_=_NextPart_001_01C1E45F.222683A0
Content-type: text/html; charset="ISO-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>How do you approach 
error trapping and use exceptions in Python to&nbsp;<SPAN 
class=700342009-15042002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>take care of it?&nbsp; 
How do you for all the possible dumb user mistakes?&nbsp;&nbsp;<SPAN 
class=700342009-15042002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=700342009-15042002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002>My tutor 
contains a page on this subject, plus we just had a thread on 
it.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=700342009-15042002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002>&gt; 
&nbsp;</SPAN>I mean give me the kind of thought process of how I should go 
about&nbsp;<SPAN class=700342009-15042002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>thinking this through 
in planning my program.<SPAN class=700342009-15042002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=700342009-15042002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>The main thing is just to think through what 
could </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>go wrong</FONT>&nbsp;<FONT face="Courier New" 
color=#0000ff>and catch those exceptions at the last point 
</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=700342009-15042002><FONT 
face="Courier New" color=#0000ff>that you can sensibly deal with 
them.</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>For production code I routinely put a try:/except/ 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>handler around my entire program which just says 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>"Oops something unexpected happened". But thats just 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>to shield the gentle users from unsightly stack traces. 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>I comment it out during 
development/testing.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=700342009-15042002>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A 
target=_blank 
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT> 
</P></SPAN></FONT></FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C1E45F.222683A0--