Errors
See also: compiling and debugging,
err, #err.
Compile-time errors
Compile-time errors are generated when compiling
macros that contain syntax errors. Macros are compiled before they start, and
don't start if there are syntax errors. The first syntax error is displayed
in the QM output like "Error in Macro: error description". Compile-time
errors are not generated in exe, because
in exe the macro is already compiled.
Some compile-time errors and possible reasons:
- unknown identifier: 1. Forgot to declare
some variable, dll function or other identifier. Declaration
must go before usage. If the identifier is declared in just imported macro
list file or just added shared file, run that function or restart QM. 2. Character
case mismatch (QM macro language is case sensitive). 3. Forgot to enclose
in quotes a string argument (window title, file path, etc). 4. The macro author
is not you, and he/she uses a newer QM version than you. Upgrade QM.
- unexpected identifier: This type of identifier cannot be used here.
- unexpected character: 1. Names of variables and other identifiers
must consist of alphanumeric characters and underscore, and cannot begin with
a digit. 2. Incorrect syntax.
- missing parts: Forgot some argument (parts) of the command.
- too many parts: 1. Forgot to enclose in parentheses function argument
which is expression with operators and contains spaces or is quite complex.
2. Forgot to enclose in quotes string argument. 3. Forgot semicolon after
statement that is followed by more statements in the same line.
- missing ( after function name, or ; after statement: 1. The same
reasons as above. 2. The ( must immediately follow function name.
- else without if: indentation (number of tabs) of else
must match indentation of associated if.
- case without sel: indentation (number of tabs) of case
must be one more than indentation of associated sel.
- expected numeric (or string) expression: 1. Used string where there
must be numeric value, or vice versa. 2. Forgot some argument.
- expected int, integer constant, etc: Similar reasons as above.
- expected int*, etc: Function expects address of variable (e.g.,
Function(&var),
but not Function(var)
). Variable type also must match expected. For type casting, use operator
+.
- ... already exists or is declared: 1. An attempt to declare a variable
or other identifier while it is already somewhere declared differently. 2.
An attempt to declare a local variable more than once in the same function.
- expected x (to y) arguments ...: Forgot some arguments. When calling
an user-defined or dll function, the number of arguments must match the number
of arguments in function's declaration (function
or dll statement), unless dll function declared
without arguments.
- syntax: other error.
- Exception while compiling: internal compiler error. Try to restart
QM.
- If a function argument is quite complex expression (e.g., a.r[i].right-a.r[i].left ), enclose it in parentheses.
- If compiler reports false error (possibly a bug), try to restart QM.
Run-time errors
Run-time errors are generated while macro is executed. By default, on a run-time
error the macro ends. In the QM output is displayed error description, like
"Error (RT) in Macro: error description".
There are three groups of run-time errors:
1. Errors that are generated by QM ("Window not found", "File
not found", etc). Such errors can be handled with the err
statement. There are also several fatal errors that cannot be handled, such
as a noncompiled function containing syntax errors.
2. Errors that are generated using the end
statement. Such errors can be handled with the err
statement.
3. Exceptions (errors generated by the operating system or components). In
most cases it is result of incorrect programming (invalid pointer, division
by 0, endless recursion, etc). Exceptions can by handled with the err
statement, but you should avoid them if possible.
Some run-time errors and possible reasons:
- Window not found: 1. Window name must match case. 2. Window is hidden:
use opt hidden 1 before, or use class name. 3. Part of window name (e.g., document
name) now is different than when recording. Use partial name.
- Menu item or button not found: 1. Underlined characters must be
preceded by &. To view underlined characters, expand menu with the keyboard
(Alt+...). 2. Nonstandard menu. 3. If button class name does not have "Button"
or "Btn", don't use but name [window],
but instead use id or child
function. 4. Button cannot be found by text because has "owner-draw"
style. Try function id, or child(x
y), or scan.
- 0x80020003, Member not found (with accessible objects): 1. The
accessible object does not support this feature. 2. Window is inactive. Use
act to activate window.
- Often reason of run-time error (e.g., "Child window not found")
is that macro that communicates with other application runs too fast. Insert
the wait command or change
macro speed (spe).