pyCAPS
pyCAPS: A Python Extension Module for CAPS
exception.py

Example of raised error (pyCAPS.CAPSError) handling in pyCAPS.

1 # Use: Test autolinking of capsValue objects
2 
3 from __future__ import print_function
4 
5 # Import pyCAPS module (Linux and OSx = pyCAPS.so file; Windows = pyCAPS.pyd file)
6 import pyCAPS
7 
8 # Instantiate our CAPS problem "myProblem"
9 print("Initiating capsProblem")
10 myProblem = pyCAPS.capsProblem()
11 
12 # Load a *.csm file "./csmData/cfdMultiBody.csm" into our newly created problem.
13 print("Loading file into our capsProblem")
14 myGeometry = myProblem.loadCAPS("./csmData/cfdMultiBody.csm")
15 
16 # Try to load another geometry into the problem - this is forbidden
17 try:
18  myGeometry = myProblem.loadCAPS("./csmData/cfdMultiBody.csm")
19 
20 except pyCAPS.CAPSError as e:
21  print("We caught the error!")
22 
23  print("Error code =", e.errorCode)
24  print("Error name =", e.errorName)
25 
26  # Do something based on error captured.
27 
28 except:
29  print ("We did not catch the error!")
30