dtml2python (sorry, forgot the subject)
Hello I didn't find the equivalent commands in python (script) for this two dmtl commands: <dtml-try> ... <dtml-except DatabaseError> <dtml-if "error_type == 'IntegrityError'"> ... </dtml-if> <dtml-else> ... </dtml-try> --- try: ... except DatabaseError: if error_type == 'IntegrityError': ... else: ... doesn't work. Have I to import something to access the variables, or what am I missing? Thanks Dieter _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
You should read the Python docs and learn how exception handling works (see try..except, traceback module etc). And btw. avoid double postings. -aj --On Montag, 26. Mai 2003 23:51 Uhr +0200 Dieter Fischer <dieter.fischer@grid-it.ch> wrote:
Hello
I didn't find the equivalent commands in python (script) for this two dmtl commands:
<dtml-try> ... <dtml-except DatabaseError> <dtml-if "error_type == 'IntegrityError'"> ... </dtml-if> <dtml-else> ... </dtml-try>
---
try: ... except DatabaseError: if error_type == 'IntegrityError': ... else: ...
doesn't work. Have I to import something to access the variables, or what am I missing?
Thanks
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hello
You should read the Python docs and learn how exception handling works (see try..except, traceback module etc).
It's not a python problem, as I wrote I just don't know how to access the variables.
except DatabaseError:
Perhaps my question was not precise. I'm using Formulator and I'm trying (a so many suggested), to convert my DTML to ZPT and Python. I want to do some error testing dependig on a database failure. But I'm always getting some: Error Type: AttributeError Error Value: DatabaseError So I googled around, but I didn't get an answer how to catch it. I've tried with context and so on, but nothing worked.
And btw. avoid double postings.
My Email reader let's me send mails without subjects (and stupid me wrote one), this gives no thread. Regards Dieter
Dieter Fischer wrote at 2003-5-26 23:51 +0200:
I didn't find the equivalent commands in python (script) for this two dmtl commands:
<dtml-try> ... <dtml-except DatabaseError> <dtml-if "error_type == 'IntegrityError'"> ... </dtml-if> <dtml-else> ... </dtml-try>
---
try: ... except DatabaseError: if error_type == 'IntegrityError': ... else: ...
doesn't work. Have I to import something to access the variables, or what am I missing?
Exception handling is nasty in Python Scripts... You must provide the necessary security declarations (read "PythonScripts --> README") and then import the exceptions you want to catch. The "except" clause has the form: except [ExceptionDesignator [, name]]: When you add the ",name", then "name" is bound to the exception value and you can in principle analyse it. But, usually, the necessary security declarations are missing. The easiest solution would be to move exception handling into an ExternalMethod (or use "XXXPythonScripts", the PythonScript without security restrictions). If this is no option for you, giving "Exception" the necessary security declaration through monkey patching might be partial solution. Dieter
participants (3)
-
Andreas Jung -
Dieter Fischer -
Dieter Maurer