Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: adding a simulation mode

Reply
Thread Tools

Re: adding a simulation mode

 
 
Prasad, Ramit
Guest
Posts: n/a
 
      07-13-2012
> > Please do NOT catch BaseException, since that is the wrong thing to do.

>
> I would agree if you had said "in production code".
>
> If you are investigating why a third-party function is stopping your
> interpreter, then catching BaseException may tell you that the code
> is raising the wrong kind of Exception. Once you know whatkind the
> function is raising, you should catch only that particularexcpetion
> subclass.


I would say the opposite. In production code usually I want it
to recover, log as much information as I need (including sending
any notifications), and NOT just die.

In development, not catching the exception will give me a full
trace back automatically. Why bother with trying to catch and
print something when the interpreter will do it for me? Not
to mention that removes any hassle of trying to catch the
"right" exception or figuring out the best way to print it.
I suppose if there are argumentson the exception that were not
printed then I might want to catch it,but has been rare
in my experience.

Ramit

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      07-13-2012
On Sat, Jul 14, 2012 at 3:08 AM, Prasad, Ramit
<> wrote:
> I would say the opposite. In production code usually I want it
> to recover, log as much information as I need (including sending
> any notifications), and NOT just die.
>
> In development, not catching the exception will give me a full
> trace back automatically.


Here's another take on the matter. In development, your script is your
execution unit, so you let the interpreter print out your tracebacks.
In production, there will usually be one, maybe two subunits (for
instance, a TCP-based server might have the socket connection as an
execution unit, and possibly a command parser inside that), and at the
top of that subunit, you have a broad exception handler that resets
that one unit (goes back and accepts another client, or waits for
another command). Otherwise, wide-scope exception handling is usually
a bad thing.

ChrisA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: adding a simulation mode andrea crotti Python 0 07-05-2012 09:22 AM
Re: adding a simulation mode Dieter Maurer Python 0 07-05-2012 08:39 AM
adding a simulation mode andrea crotti Python 4 07-04-2012 05:01 PM
Re: adding a simulation mode Devin Jeanpierre Python 0 07-04-2012 04:08 PM
Re: adding a simulation mode Mike C. Fletcher Python 0 07-04-2012 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57