MethodResult type

Note: this feature is available from version 5.4.9.

In this topic:

Description

The MethodResult type is mostly used for operation that could produce exception.
For input/output exception, instead of throwing exception in the runtime, the language returns this type of value to indicates if the operation succeed.

Properties

Success

Returns True when the operation succeed, otherwise it return False and chance is to have an ErrorMessage which indicates the reason of failure.

Return a Boolean.

Dim items As Variant
Dim result = items.LoadJSON("incorrect json format")
result.Success ' => False

 

Dim isOk As Variant
Dim result = isOk.LoadJSON("true")
result.Success ' => True

↑ Top of page ↑

ErrorCode

Returns the code of failure. It's always DK when the Success is True, or when there is no error code provided by the API that throw the exception.

Return a Number.

Dim items As Variant
Dim result = items.LoadJSON("incorrect json format")
result.Success ' => False
result.ErrorMessage ' => "SyntaxError: Unexpected token i in JSON at position : 0"
result.ErrorCode ' => DK

↑ Top of page ↑

ErrorMessage

Returns the reason of failure. It's always empty when the Success is True, and most of time non-empty when it's False

Return a String.

Dim items As Variant
Dim result = items.LoadJSON("incorrect json format")
result.Success ' => False
result.ErrorMessage ' => "SyntaxError: Unexpected token i in JSON at position : 0"

 

Dim isOk As Variant
Dim result = isOk.LoadJSON("true")
result.Success ' => True
result.ErrorMessage ' => "" 

↑ Top of page ↑

Methods

ToString

Returns a string which represent the result (express in JSON format).

Return a String.

Dim items As Variant
Dim result = items.LoadJSON("invalid json format")

 ' Output in a single line (it's break here for the readability)
result.ToString() ' => "{
    '"success":false,
    '"errorCode":-999999.99,
    '"errorMessage":"SyntaxError: Unexpected token i in JSON at position : 0"
    '}"

↑ Top of page ↑

TypeOf()

Always returns "methodresult".

Return a String.

Dim items As Variant
Dim result = items.LoadJSON("invalid json format")

result.TypeOf() ' => "methodresult"

↑ Top of page ↑

Create your own Knowledge Base