473,403 Members | 2,284 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,403 software developers and data experts.

templatetaizing exceptions

alf
Hi,

I have a few places in the code where I use:

try:
code_block
except A:
exception_handling
the code block is different each time while exception_handling the same.

What would be the best technique to abstract that out?
--
A.
Nov 13 '07 #1
3 871
En Tue, 13 Nov 2007 01:09:12 -0300, alf <as*@me.xs4all.nlescribió:
I have a few places in the code where I use:

try:
code_block
except A:
exception_handling
the code block is different each time while exception_handling the same.

What would be the best technique to abstract that out?
A function?

try:
code_block
except A:
handle_exception()

--
Gabriel Genellina

Nov 13 '07 #2
On Tue, 13 Nov 2007 06:17:26 -0300, Gabriel Genellina wrote:
>
A function?

try:
code_block
except A:
handle_exception()
maybe
>>def handle(f, *args, **kw):
.... try:
.... return f(*args, **kw)
.... except A:
.... handle_exception()
>>def doSomething():
.... code_block
....
>>handle(doSomething)
cheers
Nov 13 '07 #3
alf
david wrote:
On Tue, 13 Nov 2007 06:17:26 -0300, Gabriel Genellina wrote:
>A function?

try:
code_block
except A:
handle_exception()

maybe
>>>def handle(f, *args, **kw):
... try:
... return f(*args, **kw)
... except A:
... handle_exception()
>>>def doSomething():
... code_block
...
>>>handle(doSomething)

cheers
thx - this might work ...

--
alfz1
Nov 13 '07 #4

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

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
agi2029
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,...

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.