Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Python runtime safe?

I've made an interface using Boost Python into my C++ code, calling the Python interpreter from my C++ code. I was curious to know if there's any API function or something that can make Python run-time safe. I mean is it possible to make the interpreter skip the faults and errors if any occurred in the code?!

Thanks in advance

like image 289
Novin Shahroudi Avatar asked Jan 25 '26 02:01

Novin Shahroudi


1 Answers

Python has exception handling functionality. You can wrap any code that has the potential to create an error in a try block:

 try:
     #do risky stuff
 except Exception as e:
     print "Exception", e, "received. Code will continue to execute"
     #do other stuff that needs to be done

You can replace Exception in that code with a specific type of exception that you're expecting, such as ZeroDivisionError, and then your code will only catch that type of error.

like image 132
seaotternerd Avatar answered Jan 27 '26 17:01

seaotternerd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!