Application.GetLastError

number Application.GetLastError (

)

Example 1

nError = Application.GetLastError();

Gets the error code for the last action that was performed, and stores it in a variable named "nError."

Tip: Starting a variable name with "n" is a technique that programmers use to help themselves remember that a variable is supposed to contain a numeric value.

Example 2

errmsg = "Error #" .. Application.GetLastError().. " in " .. Debug.GetEventContext();

Uses the concatenation operator (..) to form an error message containing the last error code and the current event context and stores the error message in a variable named "errmsg."

Example 3

-- Print the specified file.
File.Print(SessionVar.Expand("%AppFolder%\\Readme.txt"));

--Check to see if an error occurred.
error = Application.GetLastError();

-- If an error occurred, display the error message.
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
end

Prints the file "Readme.txt" located in the user's application directory (%AppFolder%). If the action fails, the error code message is displayed in a dialog message.

Note: In order to expand the session variable %AppFolder% in an action, the action SessionVar.Expand must be used.

Example 4

-- Confirm that the program executable should be launched.
result = Dialog.Message("Confirm", "Are you sure you would like to launch the application?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);

-- If the user clicked the Yes button.
if (result == IDYES) then

    -- Run the installation file.
    File.Run(SessionVar.Expand("%AppFolder%\\myprogram.exe"), "", "", SW_SHOWNORMAL, false);

    -- Check to see if an error occurred when launching the file.
    error = Application.GetLastError();

    -- If an error occurred, display an error message to the user.
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    end
end

Asks the user if they would like to run the application. If they click the Yes button, the application file will be launched using the File.Run action. If the action fails, the error code message is displayed in a dialog message.

See also:  Related Actions