21.11.2014 Views

Python Programming

Python Programming

Python Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Python</strong> <strong>Programming</strong><br />

Less Basic<br />

Error Handling/Catching Exceptions<br />

What is mainly used in UCMDB: sys.exc_info()<br />

• Example:<br />

stacktrace = traceback.format_exception(sys.exc_info()[0],<br />

sys.exc_info()[1], sys.exc_info()[2])<br />

• This function returns a tuple (type, value, traceback) of three values that<br />

give information about the exception that is currently being handled :<br />

– type gets the exception type of the exception being handled<br />

– value gets the exception parameter<br />

– traceback gets a traceback object which encapsulates the call stack at<br />

the point where the exception originally occurred.<br />

37<br />

HP CONFIDENTIAL - ENABLEMENT ONLY, NOT FOR CUSTOMER USE.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!