Errors
See also: compiling and debugging,
err, #err.
Compil-time errors
Compile-time errors (when macro syntax is incorrect, variables not declared,
etc) are generated when compiling the macro, ie before it starts to execute,
or when you click menu Run -> Compile, or when you create exe.
Such errors prevent macro from starting
to execute. In the QM output is printed error description in form "Error
in Macro: error description". These errors are not generated in exe, because
there the macro is already compiled.
Below are listed 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. (QM v1.x users)
"press keys" command must have syntax key
keycodes or 'keycodes. 5. 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 construct
code in another way. 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 (it is 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 printed error description in form
"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.
Below are listed 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 syntax 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. 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).