473,804 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exceptions


Hi,

I've the following problem with try/exception.
I've a try block that will raise some exceptions.
I want the program to ignore this exceptions completely.
Is it possible?

Thanks in advance

Zunbeltz

--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |
Jul 18 '05
26 2653
Irmen de Jong <irmen@-nospam-remove-this-xs4all.nl> writes:
Zunbeltz Izaola wrote:
Possibly the code should be restructered, and re-designed; there is
always room for imporovement. But what I'm doing is not unittest. My
program is controling and instrument (an x-ray powder
diffractometer) and some parts of the instrument are not working for
the moment, so i want to disable all error i get from this instrument
(are coded like exceptions)


What I usually do in comparable situations is to write STUB code for
the parts of the system that don't work yet.
Write your stub code so that it does nothing, but doesn't raise any
exceptions too. The only thing you then have to do is write the rest
of the code as you would have done, and once the Stubbed parts work,
replace the stub code with the real code.


....and if you think you want to get exceptions later:

def fixme():
pass
Sprinkle fixme()s through your code, then redefine later:

def fixme():
raise NotImplementedE rror()
John
Jul 18 '05 #11
Zunbeltz Izaola wrote:
Peter Hansen <pe***@engcorp. com> writes:
Zunbeltz Izaola wrote:
I want to continue executing the try block from the point the
exception was raised.
Not possible except, perhaps, with a significant amount of
working involving sys.settrace(). I think you need to find
another way to solve the problem.


But what I'm doing is not unittest.


Pardon: I don't know why I thought this was related to testing
code.
My program is controling and instrument (an x-ray powder
diffractometer) and some parts of the instrument are not working for
the moment, so i want to disable all error i get from this instrument
(are coded like exceptions)


What is the interface to the instrument? Is there some sort of
driver/wrapper layer that handles the communication with the
device? Your only hope, I think, is to intercept things at
that level and avoid/trap the exceptions before they get up
to the higher level. In effect, stubs as Irmen suggested...

It sounds like you are quite capable of figuring it out at
this point, though, since all you wanted to know was whether
you could continue after an exception and now you know you
cannot. :-)

-Peter
Jul 18 '05 #12
According to Scott David Daniels <Sc***********@ Acm.Org>:
Calvin Spealman wrote:
...
Have to admit tho, a continue feature might be useful. Some languages have
this, don't they? The thing is, Where exactly to continue? Should you retry
whatever raised the exception, continue just after it, at the beginning of
that line, or what?

See this older thread:
<http://groups.google.c om/groups?threadm= 3edd6118%241%40 nntp0.pdx.net>

Xerox's experience (in deliberately removing the "continue from
exception" language feature) I found very instructive.


Are the bugs mainly in the implementation of that feature, or in user
code attempting to use said feature?

(I notice the older thread was one year ago. Is this an annual topic? ;-)

BTW, Common Lisp has this, called "restarts". There are about half a dozen
Common Lisp implementations and none appear to have gotten restarts
terribly wrong.

Cheers.
--
Ng Pheng Siong <ng**@netmemeti c.com>

http://firewall.rulemaker.net -+- Firewall Change Management & Version Control
http://sandbox.rulemaker.net/ngps -+- ZServerSSL/Zope Windows Installers
Jul 18 '05 #13
> According to Scott David Daniels <Sc***********@ Acm.Org>:
See this older thread:
<http://groups.google.c om/groups?threadm= 3edd6118%241%40 nntp0.pdx.net>

On Tue, Jun 01, 2004 at 12:59:29AM +0000, Ng Pheng Siong wrote: (I notice the older thread was one year ago. Is this an annual topic? ;-)


Perhaps the older thread had an exception, but now it's been re-started?

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAu/DWJd01MZaTXX0RA jtjAJ9U2x7VZ4Et 2LwlH7B4mFK7gXQ yEwCeKwlA
l1ze/lr+g0ena9p+Sq87 e9I=
=PqxJ
-----END PGP SIGNATURE-----

Jul 18 '05 #14
Scott David Daniels <Sc***********@ Acm.Org> writes:
Calvin Spealman wrote:
...
Have to admit tho, a continue feature might be useful. Some languages have
this, don't they? The thing is, Where exactly to continue? Should you retry
whatever raised the exception, continue just after it, at the beginning of
that line, or what?


See this older thread:
<http://groups.google.c om/groups?threadm= 3edd6118%241%40 nntp0.pdx.net>

Xerox's experience (in deliberately removing the "continue from
exception" language feature) I found very instructive.


Funny, Common Lisp (and some of its ancestors) allows you to "fiddle
things and and return as well as even return from the exception", and
people who write industrial strength applications is Common Lisp
repeatedly state that this feature allows them to write software which
is much more robust than any they would otherwise be able to
create. Some go as far as considering any language without this
feature to be fundamentally flawed. I have never heard anyone identify
this feature as a source of bugs.

So I am tempted to conclude that the Mesa implementation was flawed
.... or maybe it was just the users who were flawed. The concept itself
seems to have proven its worth over time.
Jul 18 '05 #15
Peter Hansen <pe***@engcorp. com> writes:

Pardon: I don't know why I thought this was related to testing
code.
No problem :-)
My program is controling and instrument (an x-ray powder
diffractometer) and some parts of the instrument are not working for
the moment, so i want to disable all error i get from this instrument
(are coded like exceptions)
What is the interface to the instrument? Is there some sort of
driver/wrapper layer that handles the communication with the
device? Your only hope, I think, is to intercept things at
that level and avoid/trap the exceptions before they get up
to the higher level. In effect, stubs as Irmen suggested...


Finally I do something similar to Irmen's suggestion.
It sounds like you are quite capable of figuring it out at
this point, though, since all you wanted to know was whether
you could continue after an exception and now you know you
cannot. :-)

Yes, I only wanted to know if there was an easy way to continue after
an exception; and I can't (nobody can :-)

Thanks to all for your answers (and sorry for re-starting and annual
thread)

Zunbeltz
-Peter


--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |
Jul 18 '05 #16
Scott David Daniels <Sc***********@ Acm.Org> writes:
Calvin Spealman wrote:
...
Have to admit tho, a continue feature might be useful. Some languages have
this, don't they? The thing is, Where exactly to continue? Should you retry
whatever raised the exception, continue just after it, at the beginning of
that line, or what?

See this older thread:
<http://groups.google.c om/groups?threadm= 3edd6118%241%40 nntp0.pdx.net>

Xerox's experience (in deliberately removing the "continue from
exception" language feature) I found very instructive.


Did this language support working interactively? If so I'd be pretty surprised
to hear that no one found it useful to be able to manually fix things and
continue execution; not being able to do so is presumably my number one gripe
with python [1] -- it annoys me no end if I need to start an expensive
computation from scratch because some trivial and easily fixable problem
occured towards the end of the computation (sometimes it is possible to
salvage stuff by hand by pickling things from the appropriate post-mortem
frame, but I'd *much* prefer being able to say: foo=some_value; resume).

'as
Footnotes:
[1] Number 2 would be the stupid try: finally: idiom which also seems to
screw up tracebacks (which has occasionally led me to get rid of them
completely while debugging -- surely not a good thinge). My other gripes
are again related to python's limitations for interactive software
development -- I rather like python, but I really wish it did that better.

Jul 18 '05 #17
Peter Hansen <pe***@engcorp. com> writes:
Zunbeltz Izaola wrote:

[...]
But what I'm doing is not unittest.


Pardon: I don't know why I thought this was related to testing
code.

[...]

It couldn't be that you're obsessed with unit testing, of course
<wink>.
John
Jul 18 '05 #18
I'm going to jump in here and make an observation.
It sounds like you have too much code in a single
try/except block. If you have independent calls
to instrument interface put each of them that might
fail in a separate try/except block. I've needed
to do this in an earlier project and I log errors
in a log file for review.

Something like:

try: data=getsomedat afrominstrument func1()
except:
logf.writelines ("W","Unable to communicate with func1")

try: data=getsomedat afrominstrument func2()
except:
logf.writelines ("W","Unable to communicate with func2")

My understanding is that try/except overhead is very low
(especially if there is not an exception).

HTH,
Larry Bates
Syscon, Inc.

"Zunbeltz Izaola" <zu******@wm.lc .ehu.es.XXX> wrote in message
news:ct******** *****@lcpxdf.wm .lc.ehu.es...
Peter Hansen <pe***@engcorp. com> writes:

Pardon: I don't know why I thought this was related to testing
code.


No problem :-)
My program is controling and instrument (an x-ray powder
diffractometer) and some parts of the instrument are not working for
the moment, so i want to disable all error i get from this instrument
(are coded like exceptions)


What is the interface to the instrument? Is there some sort of
driver/wrapper layer that handles the communication with the
device? Your only hope, I think, is to intercept things at
that level and avoid/trap the exceptions before they get up
to the higher level. In effect, stubs as Irmen suggested...


Finally I do something similar to Irmen's suggestion.
It sounds like you are quite capable of figuring it out at
this point, though, since all you wanted to know was whether
you could continue after an exception and now you know you
cannot. :-)


Yes, I only wanted to know if there was an easy way to continue after
an exception; and I can't (nobody can :-)

Thanks to all for your answers (and sorry for re-starting and annual
thread)

Zunbeltz
-Peter


--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |

Jul 18 '05 #19
Alexander Schmolck <a.********@gmx .net> wrote:
Did this language support working interactively? If so I'd be pretty surprised
to hear that no one found it useful to be able to manually fix things and
continue execution; not being able to do so is presumably my number one gripe
with python [1] -- it annoys me no end if I need to start an expensive
computation from scratch because some trivial and easily fixable problem
occured towards the end of the computation (sometimes it is possible to
salvage stuff by hand by pickling things from the appropriate post-mortem
frame, but I'd *much* prefer being able to say: foo=some_value; resume).
The edit-and-continue feature is also standard in the Microsoft world.
Visual C++ and Visual Basic 6.0 all have this feature. (VB.NET does
not, but they are implementing it for the version 2005 aka Visual
Studio Whidbey.) Edit-and-continue is useful debugging tool,
especially if the initial-state setup is expensive.

Python is good, but not good enough in many areas.
Footnotes:
[1] Number 2 would be the stupid try: finally: idiom which also seems to
screw up tracebacks (which has occasionally led me to get rid of them
completely while debugging -- surely not a good thinge). My other gripes
are again related to python's limitations for interactive software
development -- I rather like python, but I really wish it did that
better.


There are a few lessons learnt from younger programming languages,
like Io. One lesson is that you really would like to avoid rigid
statement syntax. In the example of the original topic of this thread,
you cannot intercept/override exception handling mechanism because the
try:...except:. .. block is not a function. Similar situations happen
with issues regarding aspect-oriented programming. In a language like
Io, everything is a method that send message to an object. Even
If(...) statements are methods, as well as loops. The advantage is you
can intercept things at your heart's content. In comparison, Python's
exception handling is not interceptible, because exception handling is
hard-coded in syntax.

It does not mean all hope is lost in Python. But it does mean that
instead of using the raise... statement in Python, you need to call a
function/method instead. You can then intercept at that level: either
by actually throwing an exception, or by redirecting it to some user
intervention funtion, or by totally ignoring it (like using a 'pass'
statement.)

Interactive programming with features like edit-and-continue still has
room to grow (most edit-and-continue features are not transactional,
that is, you cannot revert changes easily.) But in my opinion that's
an arena for prototype-based languages, and down the line, for
reversible-computing languages. Frankly, theoretically it is possible
to have a development environment where you never need to restart your
program (for non-real-time applications.)

As for Python's interactive programming, I've done some experiment
before. It's not totally impossible. It's a bit uncomfortable. Python
does have module reload and weakref. When you use these tools
properly, you can achieve a high degree of non-stop programming. It
does not come as part of the language per-se. You need to build up
some tools yourself first. But after that, you can achieve non-stop
programming, more-or-less. After all, Zope is a living example of a
Python application where you can program a lot of things, without
shutting down the server.

regards,

Hung Jung
Jul 18 '05 #20

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

Similar topics

16
5295
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 is that when an exception is raised, the destruction of locals appears to be deferred to program exit. Am I missing something? Is this behaviour by design? If so, is there any reason for it? The only rationale I can think of is to speed up...
21
2239
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 exceptions that can be raised in a Python function, or in any of the functions it calls, etc.? /Dan
26
2920
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 belief is that checked exceptions should be required in .NET. I find that many others share the same views as I do. It is extremely frustrating to have to work around this with hacks like Abstract ADO.NET and CLRxLint (which still don't solve the...
9
2343
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned with unmaintainable code (an so are now not using exceptions). My position is that "I can be convinced to use exceptions" and my experience was that it let to code that was (much) more difficult to debug. The team decided that we'd give...
6
2833
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally block, just in case there might be an exception? i.e. is it ok performance-wise to pepper pieces of code with try..catch..finally blocks that must be robust, in order that cleanup can be done correctly should there be an exception?
14
3483
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a public member with a return type that is derived from System.Exception? I understand the importance of having clean, concise code that follows widely-accepted patterns and practices, but in this case, I find it hard to blindly follow a standard...
8
2260
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an exception should be thrown only in exceptional situations. It turned out that each of my colleagues had their own interpretation about what an "exceptional situation" may actually be. First of all, myself I’m against using exceptions extensively,...
1
2393
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 look for when evaluating someone's code is a try/catch block. While it isn't a perfect indicator, exception handling is one of the few things that quickly speak about the quality of code. Within seconds you might discover that the code author...
2
2970
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It only lists NotImplementedException in the Exceptions section. (Note that it does mention WebException in the Remarks section, but who knows if this is always the case for such classes, and thus perhaps they can't be trusted to always list these, and...
0
6505
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 NullPointerException or ArrayIndexOutOfBoundsException. All of these extend the basic class Exception. In general, you can sort Exceptions into two groups: Checked and unchecked Exceptions. Checked Exceptions are checked by the compiler at compilation time. Most...
0
9716
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, 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...
0
9595
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,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9177
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, 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...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
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();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
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...

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.