Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Interapplication Communication /
Chapter 10 - Scripting Components / Scripting Components Reference
Required Scripting Component Routines / Executing and Disposing of Scripts


OSAScriptError

You can use the OSAScriptError function to get information about errors that occur during script execution.

FUNCTION OSAScriptError(scriptingComponent: ComponentInstance;
                        selector: OSType;
                        desiredType: DescType;
                        VAR resultingErrorDescription: AEDesc)
                        : OSAError;
scriptingComponent
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent (see page 10-4).
selector
A value that determines what OSAScriptError returns. The value can be one of these constants:
            CONST
               kOSAErrorNumber            = 'errn';
               kOSAErrorMessage           = 'errs';
               kOSAErrorBriefMessage      = 'errb';
               kOSAErrorApp               = 'erap';
               kOSAErrorPartialResult     = 'ptlr';
               kOSAErrorOffendingObject   = 'erob';
               kOSAErrorRange             = 'erng';
desiredType
The desired descriptor type of the resulting descriptor record. The description that follows explains how this is determined by the value passed in the selector parameter.
resultingErrorDescription
The resulting descriptor record.
DESCRIPTION
Whenever the OSAExecute function returns the error errOSAScriptError, you can use the OSAScriptError function to get more specific information about the error from the scripting component that encountered it. (This information remains available only until the next call to the same scripting component.) The information returned by OSAScriptError depends on the value passed in the selector parameter, which also determines the descriptor type you should specify in the desiredType parameter.
ConstantInformation returned in resultingErrorDescription parameter
kOSAErrorNumberError number for either system error or scripting component error. The value of desiredType must be typeShortInteger.
kOSAErrorMessageError message associated with error number, including both the name of the application and a description of the error. This constant is sufficient for simple error reporting. The value of desiredType must be typeChar or another text descriptor type.
kOSAErrorBriefMessageBrief error message associated with error number, excluding the name of the application, any partial result, and the offending object. The value of desiredType must be typeChar or another text descriptor type.
kOSAErrorAppEither the name or the process serial number (PSN) of the application that received the error, if it was the result of sending an Apple event. The value of desiredType must be typeProcessSerialNumber (for the PSN) or a text descriptor type such as typeChar (for the name).
kOSAErrorPartialResultPartial result returned after a call to AESend that failed. This consists of a reply parameter that contains some but not all of the information requested.The value of desiredType must be typeBest (for the best type) or typeWildCard (for the default type).
kOSAErrorOffendingObjectAn object specifier record for the object that caused the error. The value of desiredType must be typeObjectSpecifier, typeBest, or typeWildCard. For some scripting components, including AppleScript, these three values are equivalent.
kOSAErrorRangeRange of source data in which error occurred. The value of desiredType must be typeOSAErrorRange.

Every scripting component should support calls to OSAScriptError that pass kOSAErrorNumber, kOSAErrorMessage, or kOSAErrorPartialResult in the selector parameter.

Some scripting components may also support calls that pass other values in the selector parameter, including kOSAErrorRange, which provides start and end positions delimiting the errant expression in the source data. If the value of the selector parameter is kOSAErrorRange, the value of desiredType must be typeOSAErrorRange.

CONST typeOSAErrorRange          = 'erng';
A descriptor record of type typeOSAErrorRange is an AE record that consists of two descriptor records of typeShortInteger specified by these keywords:

CONST
   keyOSASourceStart    = 'srcs'; {start of error range}
   keyOSASourceEnd      = 'srce'; {end of error range}
If the value of the selector parameter is kOSAErrorNumber, scripting components may return, in the resultingErrorDescription parameter, one of these general error codes:
errOSACantCoerce-1700Same as errAECoercionFail; can't coerce data to requested descriptor type
errOSACantAccess-1728Same as errAENoSuchObject; runtime error in resolution of object specifier record
errOSAGeneralError-2700General runtime error
errOSADivideByZero-2701Attempt to divide by zero
errOSANumericOverflow-2702Numeric overflow
errOSACantLaunch-2703Can't launch specified file because it isn't an application
errOSAAppNotHighLevelEventAware-2704Doesn't respond to Apple events
errOSACorruptTerminology-2705The application has a corrupted 'aete' resource
errOSAStackOverflow-2706Stack overflow
errOSAInternalTableOverflow-2707Internal table overflow
errASDataBlockTooLarge-2708Attempt to create a value larger than the allowable size
errOSATypeError-1703Same as errAEWrongDataType; wrong descriptor type
errOSAMessageNotUnderstood-1708Same as errAEEventNotHandled; event not handled or message not understood
errOSAUndefinedMessage-1717Same as errAEHandlerNotFound; handler not found for message
errOSAIllegalIndex-1728Same as errAEIllegalIndex; not a valid index
errOSAIllegalRange-2720Same as errAEImpossibleRange; range of specified objects not possible
errOSASyntaxError-2740General syntax error
errOSASyntaxTypeError-2741Syntax error; parser expected one type but found another
errOSATokenTooLong-2742Identifier too long
   
errOSAMissingParameter-1701Same as errAEDescNotFound; descriptor record not found
errOSAParameterMismatch-1721Same as errAEWrongNumberArgs; wrong number of arguments
errOSADuplicateParameter-2750Parameter specified more than once
errOSADuplicateProperty-2751Property specified more than once
errOSADuplicateHandler-2752Handler defined more than once
errOSAUndefinedVariable-2753Undefined variable
errOSAInconsistentDeclarations-2754Inconsistent declarations
errOSAControlFlowError-2755Control flow error

Although scripting components are not required to support these error codes, their use simplifies error handling for applications that run scripts created by multiple components.

If the value of the selector parameter is kOSAErrorNumber, the AppleScript component may return, in the resultingErrorDescription parameter, one of these error codes:
errAECantConsiderAndIgnore-2720Can't both consider and ignore a parameter
errASCantCompareMoreThan32k-2721Can't compare text larger than 32K
errASCantCompareMixedScripts-2722Can't compare text from different script systems
errASTerminologyNestingTooDeep-2760Tell statements nested too deeply
errASInconsistentNames-2780Syntax error; names at beginning and end of handler are inconsistent (AppleScript English dialect only)

SPECIAL CONSIDERATIONS
If you call OSAScriptError using an instance of the generic scripting component, the generic scripting component uses the same instance of a scripting component that it used for the previous call.

RESULT CODES
noErr0No error
errOSACantCoerce-1700Desired type not supported by scripting component
errOSASystemError-1750General scripting system error
errOSABadSelector-1754Selector value not supported by scripting component
badComponentInstance$80008001Invalid component instance
SEE ALSO
For an example of the use of OSAScriptError, see Listing 10-3 on page 10-11.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996