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.ini t(type_conv=200 )
con = kinterbasdb.con nect(host=h, database=d,user =u, password=p)
cur = con.cursor()
insertStatement = cur.prep("some SQL statement...... ")
cur.executemany (insertStatemen t, 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 2 2990
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 aC++ exception handling has no significant performance impact at
compile-time or run-time.
We have not found this to be the case at all.
|
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 "resources" I use
are memory and file I/O and whenever there is a memory allocation
failure or file I/O failure I just simply call a custom assert-type
function to check, print a error message and abort. This seems to be OK
for now (for the...
|
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 exception
handling mechanism which will allow me to pass character information
about an error and its location from lower-level classes.
Can you please critique the following exception handling mechanism in
terms of my requirements ?
|
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. How do they track which auto objects have been constructed, and in which
order?
2. Where is the code stored that implements stack unwinding?
|
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 the best thing to do:
1. Dont catch the exception in DAL and let it prop up to the Application level and the Global.Application_Error event log it to any source and show let ASP.NET show custom error page provided in Web.Config file.
OR
2....
| |
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.
I don't have a centralized page for all error. What are some good ways
that I can centralize my error handling and take control, in one place, of
all my exception messages for my user?
|
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.
I created a project and added the following references -
1/ Enterprise Library Exception Handling Application Block v 4.0
|
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, especially as
programs get large.
Most of the issues of exceptions are not specific to Python, but I
sometimes feel that Python makes them more acute because of the free-n-
easy manner in which it employs exceptions for its own uses and allows
users...
|
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 the Diagnostic Stack
but that doesn't tell me what line caused the problem. I'm generally doing
this for the type Exception because I don't know what all errors will
happen.
Anybody have any thoughts?
TIA - Jeff.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |