473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

what is the reasonable (best?) Exception handling strategy?

I am a little bit confused by all possibilities for exceptions handling
in Python (probably because I am not skilled enough??) I did try to
search trough this list and reading Python tutorial about Errors and
Exceptions but didn't find some "general" answer about exception
handling policy (strategy).

In the following example each row can IMHO raise an exception (if the
Firebird service is not running for example, if the database is
corrupted etc.).

Do I have to write "try/except" clause on each row?

Or to write try/except block (function) where to handle (on one place)
all exceptions expected in the program code is a good idea?

Or do I have to write own "exception hook"?

What about unexpected exceptions? :(

def databasExample(h,d,u,p):
import kinterbasdb; kinterbasdb.init(type_conv=200)
con = kinterbasdb.connect(host=h, database=d,user=u, password=p)
cur = con.cursor()
insertStatement = cur.prep("some SQL statement......")
cur.executemany(insertStatement, ListOfValues)
con.commit()
cur.close()

Generally I am trying to find some general advices or suggestions about
exception handling more than the specific answers to the above
mentioned code example.

Regards

Petr Jakes

Jun 1 '06 #1
2 2962
Petr Jakes wrote:
I am a little bit confused by all possibilities for exceptions handling
in Python (probably because I am not skilled enough??) I did try to
search trough this list and reading Python tutorial about Errors and
Exceptions but didn't find some "general" answer about exception
handling policy (strategy).
It depends on what you are actually able to do about the exception. If you
can recover from it meaningfully then you may want to handle it near the
place it is thrown. If all you can do is abort the entire program then you
handle that at the outermost level of the program.

In the following example each row can IMHO raise an exception (if the
Firebird service is not running for example, if the database is
corrupted etc.).
If a service isn't running that sounds pretty fatal. Handle it at the outer
levels of your code. If the database is corrupted that might also be
terminal unless you include bad data (e.g. invalid email address) in that
definition, in that case it may be something you can fix, ignore, or live
with: it should be obvious in this case where in your code you need to do
the fixup or ignoring.

Do I have to write "try/except" clause on each row?
The processing you perform on a row might raise an exception for which the
correct action would be to simply continue with the next row. In that case
handle the exception inside the 'processRow' function so the code which
iterates over the rows never sees it. If it is a more serious problem which
is going to stop you processing any further rows then you let it propogate.

Or to write try/except block (function) where to handle (on one place)
all exceptions expected in the program code is a good idea?

Or do I have to write own "exception hook"?

What about unexpected exceptions? :(


Big errors, or unexpected errors you handle in one place usually by making
sure a human is alerted to the problem.
Jun 1 '06 #2
Petr Jakes:
What about unexpected exceptions? :(


I asked a similar question some time ago:
http://groups.google.nl/group/comp.l...963b99da4b2653

--
René Pijlman
Jun 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: zzfreddybb | last post by:
We are using HP aCC compiler on a HP Itanium box ( 11.23) We are having some severe performance hits using exception handling ( try/catch ) scenarios. The online aCC documentation says: HP...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
3
by: Dave Rahardja | last post by:
Don't know if this is a C++ /language/ question, but I think this may be the best place to ask. What's a typical implementation of the exception handling mechanism in C++? Specifically... 1....
2
by: Rajeev Soni | last post by:
Hi, Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is...
1
by: Do | last post by:
Hi, I would like to hear about everybody's exception handling strategies. I currently just catch my exceptions and display all my messages on the page that the exceptions occurs, in a label. ...
0
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have previously used EL v 3.1 Exception Handling application block successfully. I thought I would now try to do the same with EL v 4.0. My first experiment was to replace an exception....
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
1
by: Mufasa | last post by:
I'm trying to modify my exception handler to give me as much useful information as possible. One of the thigs I would like to know is where in the code the error actually happened. I can print out...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.