<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 21-02-2010 03:51, Ryan Kelly wrote:
<blockquote cite="mid:1266720681.3908.24.camel@durian" type="cite">
<pre wrap="">On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 02/21/10 12:02, Stef Mientki wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 21-02-2010 01:21, Lie Ryan wrote:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><a class="moz-txt-link-rfc2396E" href="mailto:stef.mientki@gmail.com"><stef.mientki@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">hello,
I would like my program to continue on the next line after an uncaught
exception,
is that possible ?
thanks
Stef Mientki
</pre>
</blockquote>
</blockquote>
<pre wrap="">That reminds me of VB's "On Error Resume Next"
</pre>
</blockquote>
<pre wrap="">I think that's what I'm after ...
</pre>
</blockquote>
<pre wrap="">
A much better approach is to use callbacks, the callbacks determines
whether to raise an exception or continue execution:
def handler(e):
if datetime.datetime.now() >= datetime.datetime(2012, 12, 21):
raise Exception('The world has ended')
# else: ignore, it's fine
def add_ten_error_if_zero(args, handler):
if args == 0:
handler(args)
return args + 10
print add_ten_error_if_zero(0, handler)
print add_ten_error_if_zero(10, handler)
print add_ten_error_if_zero(0, lambda e: None) # always succeeds
</pre>
</blockquote>
<pre wrap="">
Or if you don't like having to explicitly manage callbacks, you can try
the "withrestart" module:
<a class="moz-txt-link-freetext" href="http://pypi.python.org/pypi/withrestart/">http://pypi.python.org/pypi/withrestart/</a>
It tries to pinch some of the good ideas from Common Lisp's
error-handling system.
from withrestart import *
def add_ten_error_if_zero(n):
# This gives calling code the option to ignore
# the error, or raise a different one.
with restarts(skip,raise_error):
if n == 0:
raise ValueError
return n + 10
# This will raise ValueError
print add_ten_error_if_zero(0)
# This will print 10
with Handler(ValueError,"skip"):
print add_ten_error_if_zero(0)
# This will exit the python interpreter
with Handler(ValueError,"raise_error",SystemExit):
print add_ten_error_if_zero(0)
Cheers,
Ryan
</pre>
</blockquote>
<font size="+1">thanks Ryan (and others),<br>
<br>
your description of withstart was very informative,<br>
and I think I understand why it's impossible what I want<br>
(something like madExcept for Delphi / C / C++, see<br>
<b><a class="moz-txt-link-freetext" href="http://www.madshi.net/madExceptDescription.htm">http://www.madshi.net/madExceptDescription.htm</a> )<br>
</b><br>
It are not the bugs that you can predict / expect to catch,<br>
but the uncaught bugs.<br>
<br>
So made some first steps,<br>
and this seems to be sufficient for now,<br>
if you're interested, look here, <br>
<a class="moz-txt-link-freetext" href="http://mientki.ruhosting.nl/data_www/pylab_works/pw_bug_reporter.html">http://mientki.ruhosting.nl/data_www/pylab_works/pw_bug_reporter.html</a><br>
<br>
cheers,<br>
Stef<br>
<br>
<br>
<br>
</font>
</body>
</html>