Exception Handling

  • Thread starter Manish Kumar (WT01 - Software Products & OSS)
  • Start date
M

Manish Kumar (WT01 - Software Products & OSS)

Hi,

We have some modules of our project implemented in python and some in C.
We use shared library objects to access C functions from python.

We need to catch the exceptions like segmentation fault occurring in the
C module in python and print the complete stack.

We tried 1) signal.signal(SIGSEGV, handler_function)
2) try:
call to C functions through shared object
except:
traceback.print_exc(file=sys.stdout)
We got this.
1) But it hangs the process.

2) It does not print the stack.

Can you please suggest some solutions ?

Thanks and Regards
Manish Kumar



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com
 
S

Sheldon

Hi,
This is a non-trivial thing that you are trying to do. You can use some
of python's built-in exceptions, like RuntimeError or IOError and if so
then:
try:
call C
except IOError, e:
print e

But this will return and print only IOErrors if they occur.

You can define your own error handling using the function RAISE:
try:
Call C
except:
raise my_error.

A catch-all error is RuntimeError; try this first.
try:
call C
except RuntimeError, r:
print r

You can read up on it here:
http://docs.python.org/api/standardExceptions.html


Cheers,
Sheldon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

error 4
Problem with proxies 3
Python IDLE 2
importing module 0
soap library for python-3.x 0
variadic function 27
Exception Handling 33
Closure/method definition question for Python 2.7 2

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top