A Display Name A Display Name - 1 year ago 109
Python Question

Python - Test For Error

In my program, It sometimes encounters an error. The only way to stop the error, is to restart the program.

So how could I get python to know when there is an error?

Example - If there is an error, close down the program.

How do I do this - Thanks!

Answer Source

That is called exception handling. You should read about it.

The basic syntax is the following:

    code that might give an error (aka exception)
except TheExceptionExpected:
    thing to do if error happends
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download