All Error functions
All functions which have an errorhandling will return error information.
Name | Function header | Example | Result | Description | Errorhandling |
---|---|---|---|---|---|
addError | func ( err error ) bool | [[ addError (newError "my Error: This is a test string" )]] |
“my Error: This is a test string” | adds an additional error message to the error object | |
clearErrors | func () bool | [[ clearErrors ]] |
true | reset all errors | |
getError | func () string | [[ getError ]] |
result on console: “illegal base64 data at input byte 4” | contains the error message (1st error) | |
getErrors | func () (tplerr []string) | [[ getErrors ]] |
result on console: “illegal base64 data at input byte 4” “my Error: This is a test string” |
returns all errors | |
hasErrors | func () bool | [[ hasErrors ]] |
if error = true / no error = false | checks the command for errors | |
newError | func ( text string ) error | [[ $result := newError "This is a test string" ]] |
$result = “This is a test string” | returns an error that formats as the given text |
func ( err error ) bool
The addError
function adds an additional error message to the error object.
Examples
[[ addError (newError "my Error: This is a test string" ) ]]
[[ $result := getError ]]
$result = "my Error: This is a test string"
[[ $result := getErrors ]]
$result = "my Error: This is a test string"
_comment testcase clearErrors and then make an error and show the error value(s)
[[ clearErrors ]]
[[ b64dec "This is a test string" ]]
[[ addError (newError "my Error: b64dec" )]]
[[ $result := getError ]]
$result = "illegal base64 data at input byte 4"
[[ $result := getErrors ]]
$result = [ "illegal base64 data at input byte 4", "my Error: b64dec" ]
_comment testcase with custom variables in error message and show all errors
[[ $x := "This is a 2nd test string" ]]
[[ b64dec $x ]]
[[ addError (newError (print "my Error: " $x ) )]]
[[ $result := getError ]]
$result = "illegal base64 data at input byte 4"
[[ $result := getErrors ]]
$result = [ "my Error: This is a test string", "illegal base64 data at input byte 4", "my Error No 2: ...string" ]
_comment clearError and then addError. So we got only the last one
[[ clearErrors ]]
[[ addError (newError (print "my Error: " $x ) )]]
[[ $result := getError ]]
$result = "my Error: This is a 2nd test string"
[[ $result := getErrors ]]
$result = [ "my Error: This is a 2nd test string" ]
func () bool
The clearErrors
function reset all errors.
Application notes / Limits:
Examples
_comment test cases with given values
_comment prepare test case and present eror
[[ addError (newError "my Error: This is a test string" )]]
[[ $result := clearErrors ]]
$result = true
_comment clearErrors and present result
[[ $result := clearErrors ]]
$result = true
func () string
The getError
function contains the error message.
Application notes / Limits:
Examples
_comment create an error and getError
[[ b64dec "This is a test string" ]]
[[ $result := getError ]]
$result = "illegal base64 data at input byte 4"
func () (tplerr []string)
The getErrors
function returns all errors in a string array.
Examples
_comment create an error and getErrors
[[ b64dec "This is a test string" ]]
[[ $result := getErrors ]]
$result = "[ "illegal base64 data at input byte 4" ]"
[[ b64dec "This is a test string" ]]
[[ addError (newError (print "my Error" ) )]]
[[ $result := getErrors ]]
$result = "[ "illegal base64 data at input byte 4", "my Error" ]
_comment testcase with custom variables in error message and show all errors
[[ $x := "This is a test string" ]]
[[ b64dec $x ]]
[[ addError (newError (print "my Error: " $x ) )]]
[[ $result := getErrors ]]
$result = "[ "illegal base64 data at input byte 4", "my Error: This is a test string" ]"
func hasErrors() bool
The hasErrors
function checks the command for errors.
Examples
_comment create an error and hasErrors
[[ b64dec "This is a test string" ]]
[[ $result := hasErrors ]]
$result = true
_comment testcase with custom variables in error message and show all errors
[[ clearErrors ]]
[[ $x := "This is a test string" ]]
[[ b64dec $x ]]
[[ addError (newError (print "my Error: " $x ) )]]
[[ $result := hasErrors ]]
$result = true
func New( text string ) error
The newError
function returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.
Examples
[[ $result := newError "This is a test string" ]]
$result = "This is a test string"