Exceptions and Python Scripts
Hi, I'd like to do a try...except in a Python Script. Unfortunately, it doesn't look like I'm allowed to import the exceptions module: Error Type: ImportError Error Value: import of "Exceptions" is unauthorized Is that intended? Where should I get hold of exception classes to use in Python Scripts? To make matters worse, a lot of Zope's internals still throw string based errors, so a very general except clause is the only way to catch them. Unfortunately, the only way to analyise those exceptions is to use sys.exec_info(), but using that in a python script always throws up an authenticatino box. Any ideas how to solve these problems? cheers, Chris
From: "Chris Withers" <chrisw@nipltd.com>
I'd like to do a try...except in a Python Script.
Unfortunately, it doesn't look like I'm allowed to import the exceptions module:
You shouldn't need to; most of the Exceptions are builtins. Cheers, Evan @ digicool
From: "Chris Withers" <chrisw@nipltd.com>
I'd like to do a try...except in a Python Script.
Unfortunately, it doesn't look like I'm allowed to import the exceptions module:
You shouldn't need to; most of the Exceptions are builtins.
Hmmm... Exceptions.Exception isn't :-S Any idea how I'd go about catching an analysing string exceptions in Python Scripts? cheers, Chris
From: "Chris Withers" <chrisw@nipltd.com>
Hmmm... Exceptions.Exception isn't :-S
Any idea how I'd go about catching an analysing string exceptions in Python Scripts?
Is there any specific exception that you are interested in catching, but can't? try: # whatever except: # Handle Exception ...will work without needing Exception itself. Cheers, Evan & digicool
Evan Simpson wrote:
Is there any specific exception that you are interested in catching, but can't?
Exceptions.Exception was the example I mentioned...
try: # whatever except: # Handle Exception
...will work without needing Exception itself.
Okay, the real problem is twofold: 1. Zope is littered with string exceptions 2. Catching exceptions that you didn't mean to is a Real Bad Thing (tm) Put these two together and and you need to use sys.exc_info() to analyse the type and value to decide whether you should re-raise it or not. Of course, you're not allowed to import anything from sys in Python Scripts so you're left with no options. Any ideas? cheers, Chris
I faced this exact problem -- catching specific Zope exceptions and re-raising others -- and that necessary sys.exc_info() route of doing that is pretty ugly. Is there a plan for moving to class-based exceptions, or would that break too much code that assumes the current string exceptions? In my experience, Python Scripts, because of their security-related limitations, are capable of only trivial functionality that isn't that much harder to do in DTML. I'd prefer to do most all Zope development in unfettered Python and some clean templating system -- and the recently published roadmap doc suggests that this may be possible later -- but the current TTW-editing architecture makes this hard to do. Both External Methods and Products require hacking directly on source files, although I suppose some hack with LocalFS could make those files accessible TTW. On Wed, Feb 21, 2001 at 03:10:26PM +0000, Chris Withers wrote:
Okay, the real problem is twofold:
1. Zope is littered with string exceptions 2. Catching exceptions that you didn't mean to is a Real Bad Thing (tm)
Put these two together and and you need to use sys.exc_info() to analyse the type and value to decide whether you should re-raise it or not.
-- Fred Yankowski fred@OntoSys.com tel: +1.630.879.1312 Principal Consultant www.OntoSys.com fax: +1.630.879.1370 OntoSys, Inc 38W242 Deerpath Rd, Batavia, IL 60510, USA
participants (3)
-
Chris Withers -
Evan Simpson -
Fred Yankowski