5.5 Error handling in the ABAQUS Scripting Interface

The basics of Python's exception handling are described in Error handling, Section 4.6.4; and the same techniques apply to the ABAQUS Scripting Interface. If certain circumstances arise while a script is running, Python allows you to take the necessary action and still allows the script to continue. Alternatively, when ABAQUS/CAE issues (or “throws”) an exception and the exception is not handled by the script, ABAQUS/CAE displays the exception message in the message area and the script stops executing.

The following topics are covered:


5.5.1 Standard Python exceptions

Python exceptions arise from either system-related problems, such as a disk or network error, or from programming errors, such as numeric overflow or reference to an index that does not exist. Standard Python exceptions are not described in this manual and are not listed as possible exceptions in the ABAQUS Scripting Reference Manual.

Look at the standard Python documentation on the official Python web site (www.python.org) for a list of standard Python exceptions. Standard exceptions are described in the Built-in Exceptions section of the Python Library Reference.


5.5.2 Standard ABAQUS Scripting Interface exceptions

Standard ABAQUS Scripting Interface exceptions arise from errors in a script that relate to ABAQUS/CAE. The standard ABAQUS Scripting Interface exceptions that can be raised by a method are listed with each command in the ABAQUS Scripting Reference Manual. The standard ABAQUS Scripting Interface exception types are listed below:

InvalidNameError

You specified an invalid name. ABAQUS/CAE enforces a naming convention for objects that you create. Names must adhere to the following rules:

  • The name can have up to 38 characters.

  • The name can include spaces and most punctuation marks and special characters.

    Warning:  While Python allows most punctuation marks and special characters, some of the strings you provide will be used in an ABAQUS input file; therefore, you cannot use the following characters: $&*~!()[]{}|;'`",.?/\ when you are naming a model or job, for example.

  • The name must not begin with a number.

  • The name must not begin or end with an underscore or a space.

  • The name must not contain a period or a double quote.

RangeError

A numeric value is out of range.

AbaqusError

Context-dependent message.

Note:  The command descriptions in the ABAQUS Scripting Reference Manual list the type of standard ABAQUS Scripting Interface exceptions that can occur; however, the exception messages are not included with the command description.


5.5.3 Additional ABAQUS Scripting Interface exceptions

Each command in the ABAQUS Scripting Reference Manual lists the standard ABAQUS Scripting Interface exceptions that can be raised by a command. In addition, if the exception is not a standard Python or ABAQUS Scripting Interface exception, the description lists the following:

  • A brief description of the problem.

  • The exception type.

  • The exception message.

For example, Figure 5–1 shows the layout of a typical exception description in the online documentation.

Figure 5–1 The layout of a typical exception description in the online documentation.

You use the exception type in your error handling routines.


5.5.4 Exception handling

The Python exception handling techniques described in Error handling, Section 4.6.4, apply to the ABAQUS Scripting Interface. You should use the command description in the ABAQUS Scripting Reference Manual to decide for which exception types you need to account. For example, the following ABAQUS Scripting Interface script attempts to create a viewport and prints a message if the width or height are too small:

try:
    session.Viewport(name='tiny',width=1, height=1)
except RangeError, message:
    print 'Viewport too small:', message
print 'Script continues running and prints this line'
The resulting output is
Viewport too small: width must be a Float >= 30
Script continues running and prints this line
The exception has been handled, and the script continues.