spss.GetLastErrorLevel and spss.GetLastErrorMessage Functions (Python)

spss.GetLastErrorLevel(). Returns a number corresponding to an error in the preceding Python Integration Package for IBM® SPSS® Statistics function.

  • For the spss.Submit function, it returns the maximum IBM SPSS Statistics error level for the submitted command syntax. IBM SPSS Statistics error levels range from 1 to 5. An error level of 3 or higher causes an exception in Python.
  • For other functions, it returns an error code with a value greater than 5.
  • Error codes from 6 to 99 are from the IBM SPSS Statistics XD API.
  • Error codes from 1000 to 1064 are from the Python Integration Package.

IBM SPSS Statistics error levels (return codes), their meanings, and any associated behaviors are shown in the following table.

Table 1. IBM SPSS Statistics error levels
Value Definition Behavior
0 None Command runs
1 Comment Command runs
2 Warning Command runs
3 Serious error Command does not run, subsequent commands are processed
4 Fatal error Command does not run, subsequent commands are not processed, and the current job terminates
5 Catastrophic error Command does not run, subsequent commands are not processed, and the IBM SPSS Statistics processor terminates

spss.GetLastErrorMessage(). Returns a text message corresponding to an error in the preceding Python Integration Package for IBM SPSS Statistics function.

  • For the spss.Submit function, it returns text associated with the highest level error for the submitted command syntax.
  • For other functions in the Python Integration Package, it returns the error message text from the IBM SPSS Statistics XD API or from Python.

Example

DATA LIST FREE/var1 var2.
BEGIN DATA
1 2 3 4
END DATA.
BEGIN PROGRAM.
try:
  spss.Submit("""
COMPUTE newvar=var1*10.
COMPUTE badvar=nonvar/4.
FREQUENCIES VARIABLES=ALL.
""")
except:
  errorLevel=str(spss.GetLastErrorLevel())
  errorMsg=spss.GetLastErrorMessage()
  print("Error level " + errorLevel + ": " + errorMsg)
  print("At least one command did not run.")
END PROGRAM.
  • The first COMPUTE command and the FREQUENCIES command will run without errors, generating error values of 0.
  • The second COMPUTE command will generate a level 3 error, triggering the exception handling in the except clause.