Go to: Synopsis. Return value. Keywords. Related. Flags. Python examples.

Synopsis

error([noContext=boolean], [showLineNumber=boolean])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

error is NOT undoable, NOT queryable, and NOT editable.

The error command is provided so that the user can issue error messages from his/her scripts and control execution in the event of runtime errors.

The string argument is displayed in the command window (or stdout if running in batch mode) after being prefixed with an error message heading and surrounded by //.

The error command also causes execution to terminate with an error. Using error is like raising an exception because the error will propagate up through the call chain. You can use catch to handle the error from the caller side. If you don't want execution to end, then you probably want to use the warning command instead.

Return value

None

Keywords

debug, information, echo

Related

warning

Flags

noContext, showLineNumber
Long name (short name) Argument types Properties
noContext(n) boolean create
Do not include the context information with the error message.
showLineNumber(sl) boolean create
Obsolete. Will be deleted in the next version of Maya. Use the checkbox in the script editor that enables line number display instead.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds


import maya.cmds as cmds
def lightError():
    l = cmds.ls( lights=True )
    if len(l) == 0:
        cmds.error( "No Lights" )
lightError()

# The above will produce the following output and raise a RuntimeError
# exception from the script containing it:
#
#   # Error: No Lights #
#
# If the option to display line numbers or the stack trace is turned on
# the following output will be produced and the same exception raised:
#
#   # Error: line 13 of 'lightError' in '<maya console'>: No Lights #
#