Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Handling exception thrown by Boost.Python c-extension in Python code

Reply
Thread Tools

Handling exception thrown by Boost.Python c-extension in Python code

 
 
MarkE
Guest
Posts: n/a
 
      03-27-2007
I'm just getting started on Boost Python and may have missed this
obvious looking problem somewhere.

Given a c-extension "testext" written using Boost Python containing a
base class "Base", a derived class "Derived", and a function
"doSomething" which expects a "Derived" parameter, if I pass it a
"Base" parameter an exception is thrown. This is a
Boost.Python.ArgumentError. My question is how do I catch this error ?

I tried the following bit of investigation:
#Start code
import testext
b = testext.Base()
try:
testext.doSomething(b)
except Exception, e:
pass
help(e.__class__)
#End code

which produces
#Start output
Help on class ArgumentError:

class ArgumentError(exceptions.TypeError)
| Method resolution order:
| ArgumentError
| exceptions.TypeError
| exceptions.StandardError
| exceptions.Exception
|
| Methods inherited from exceptions.Exception:
|
| __getitem__(...)
|
| __init__(...)
|
| __str__(...)
#End output

"print e" produces "<Boost.Python.ArgumentError instance>"

So I could handle this by writing an except clause for TypeError.

Boost.Python doesn't exist as a module i.e. it's not in sys.modules,
and I don't know how to import it - should there be a Boost.Python
module somewhere on my PythonPath that I've forgotten to setup ?
Is there a standard way of catching these errors by their actual
type ?
Is there an easy way to export the exception classes from my c-
extension (testext) so that I can use that ? Thus "except
testext.ArgumentError" would catch the "Boost.Python.ArgumentError" ?

Thanks for any help,
Mark

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
Exception has been thrown by the target of invocation exception =?Utf-8?B?VmFs?= ASP .Net 0 06-08-2005 05:11 PM
Exception has been thrown by the target of invocation exception Val ASP .Net Security 0 06-08-2005 05:10 PM
Exception of type System.Exception was thrown Selen ASP .Net 0 05-28-2004 07:19 AM
line number of the source code in the thrown exception Ahmed Moustafa Java 10 07-17-2003 06:15 PM



Advertisments