Exception Handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manish Kumar (WT01 - Software Products & OSS)

    #1

    Exception Handling


    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(S IGSEGV, handler_functio n)
    2) try:
    call to C functions through shared object
    except:
    traceback.print _exc(file=sys.s tdout)
    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.

    As a global leader, Wipro blends consulting and AI expertise across design, engineering and operations to accelerate business transformation and deliver future-ready technology.

  • Sheldon

    #2
    Re: Exception Handling

    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:



    Cheers,
    Sheldon

    Comment

    Working...