Exception handling

Here is an example of how to catch an exception and print the available information.

#!/usr/local/bin/python
import sys; 
from PyTango import *
    
try:
    mot = DeviceProxy( "notExist")
except DevFailed:
    extype, value = sys.exc_info()[:2]
    print( "Failed with exception ", extype)
    for err in value:
        print( " reason ", err.reason)
        print( " desc ", err.desc)
        print( " origin ", err.origin)
        print( " severity ", err.severity)
    sys.exit()
except:
    print( " Failed to access ", name)
    print( sys.exc_info()[0])
    sys.exit()

Here is an alternative method. It prints the exception to standard output:

#!/usr/local/bin/python
import sys; 
from PyTango import *
    
try:
    mot = DeviceProxy( "notExist")
except DevFailed as e:
	Except.print_exception( e)
    sys.exit()
except:
    print( " Failed to access ", name)
    print( sys.exc_info()[0])
    sys.exit()