Exception handling front arena
you can use the python exception mechanism to handle exceptions. A couple of simple examples describing this process are as follows.
import acm
msg = 'Zero or one stocks expected'
try:
stock = acm.FStock.Select01("contractSize=1",msg)
except RuntimeError , e:
print e
As mand stocks could have a contract size of one, the value of e is the value of msg passed to the select01() method.
import acm
a= acm.FArray()
a[0] = "FRED"
try:
print a.IntAt(0)
except TypeError , e:
print e
Note that the value of e in these examples is the same as would be returned with this statement:
print acm.LastError().Message()
The benefiy of using the LastError() method is that if youask the object it returns its class with the ClassName() method, it will tell you the type of error that ACM has detected.
- MariaS's blog
- Login or register to post comments
Delicious
Digg
Facebook
Technorati