try - executes a command/script catching any error and allowing to react on this error
Executes a command in the given level and returns the result of this command.
If the execution of the command causes an error or raises an exception, than this error or exception is catched and the error message or error depending result will be returned.
In the case of an error or exception try looks if the exception matches to one of the given exceptions behind a keyword catch. If the raised exception matches the command behind the exception will be executed. Matches no one of the given exceptions the try command looks for the keyword finally to execute the given command behind this keyword.
If one or more catch keywords are given and no given exception matches to the raised one and if there is no finally command given than the try command will raise the original raised error or exception.
The given level must have following values:
-
-level level
-
With this option try executes every command in the given level/scope. The level is the number of levels/scopes to step up from the current or with a leading # the absolute number of an existing level. The syntax is the same the command uplevel uses.
-
-global
-
With this option try executes every command in the global scope/context.
If the option
level is omitted the given
commands are executed in the current level/scope.
try sets global variables to contain informations about the last error/exception. All "Common" variables keep informations belonging to the first command executed by try. All "Catch" variables hold informations to the executed catch-command and the "Finally" variables informations to the executed finally-command. The variables could be accessed inside the of the catch- or finally-commands and outside the try-command:
-
TRYCommonResult
-
Keeps the result of the the first command executed by try.
-
TRYCommonErrorName
-
Keeps the name of the last raised exception.
-
TRYCommonErrorMsg
-
Keeps the error message of the last occurred error/exception.
-
TRYCommonErrorInfo
-
Keeps the error info (trace back) of the last occurred error/exception.
-
TRYCommonErrorCode
-
Keeps the error code of the last occurred error/exception.
-
TRYCatchResult
-
Keeps the result of the the catch-command executed by try.
-
TRYCatchErrorName
-
Keeps the name of the last raised exception.
-
TRYCatchErrorMsg
-
Keeps the error message of the last occurred error/exception.
-
TRYCatchErrorInfo
-
Keeps the error info (trace back) of the last occurred error/exception.
-
TRYCatchErrorCode
-
Keeps the error code of the last occurred error/exception.
-
TRYFinallyResult
-
Keeps the result of the the finally-command executed by try.
-
TRYFinallyErrorName
-
Keeps the name of the last raised exception.
-
TRYFinallyErrorMsg
-
Keeps the error message of the last occurred error/exception.
-
TRYFinallyErrorInfo
-
Keeps the error info (trace back) of the last occurred error/exception.
-
TRYFinallyErrorCode
-
Keeps the error code of the last occurred error/exception.