Generate run-time error


end [errorstring] [flags] [errorcode]



errorstring - error description. Can be string or variable of type QMERROR.



Where to generate error:

  • 0 (default) - in caller. If there is no direct caller - here.
  • 1 - here.
  • 2 - in caller that is not class member function called for this variable.
  • 3 - this flag is obsolete.
    In caller of first function that is not in private folder. This flag does not work in exe.

See also: opt noerrorshere, nowarningshere

4 Don't open macro. You also can set this globally in Options.
8 QM 2.3.3. Generate warning, not error.
16 QM 2.3.5. Append last dll error string. See str.dllerror.
32 QM 2.3.6. Temporary warning. It will be shown withing 1 hour after editing the macro where it would be generated. In exe the warning will never be shown. Flag 8 is optional.

errorcode - dll error code to use with flag 16. If omitted or 0, calls GetLastError.



Generates run-time error, which ends thread (running macro) if not handled.


By default, if end is used in a user-defined function, the error is generated in caller (macro/function that called the function).


Caller can handle errors with err statement. Then it may want to know error code. It is _error.code. There are several ways to set error code when generating error:


QM 2.3.3. If used flag 8, generates warning instead of error. It does not end macro. Just displays warning message in QM output. Flags 0-3 are applied. To disable such warnings, use opt nowarnings 1.


In function help you can see errors that the function may generate. QM displays errors from end statements used in that function, or errors explicitly specified in Errors: line.


end without arguments (just end) ends thread without generating error. But usually it's better to use ret. In some cases it's better to use shutdown -7. Don't use Windows API functions such as ExitThread, because then QM cannot manage threads properly.


end immediately ends execution of current function and its callers. However class destructor functions and functions registered with atend will be executed.


Avoid end (except to generate warning (flag 8)) in callback functions (dialog procedures, COM event functions, etc), unless really necessary. Also, avoid unhandled run-time errors there. If the callback function is called by a dll function, the dll may not free its allocated memory, critical sections, etc; in some cases the dll function will not work properly next time (need to restart QM). If the callback function is called with call, the caller cannot handle the error with err. The error is generated in the callback function, not in its caller.


Don't use end (except to generate warning (flag 8)) in class constructor, destructor and operator= functions and functions registered with atend. Also, avoid unhandled run-time errors there. In destructor and atend function it just ends the function, not thread. In constructor and operator= it always generates error that cannot be handled; if constructor fails, destructor calling behavior is undefined. If destructor or atend function can fail, it should handle errors (use err if need) and use end with flag 8 (warning) if need. If constructor or operator= can fail, move the code to a member function that must be explicitly called (like Class var.Init or var.Clone(var2)).


end in a special thread (QM thread or trigger filter function) just ends the callback function, not the thread.


See also: ret, #ret



end "file not found"
end "2000 my error description" ;;use an error code
end ERR_FILE ;;use an error constant

str filevariable="Z:\file"
end F"{ERR_FILE}: '{filevariable}'"

run "abc"
	_error.description + " abc"
	end _error

end ;;end thread without generating error