Libraries: MQL Plus Enhanced Error Handler Support

 

MQL Plus Enhanced Error Handler Support:

An (optional) include file to enhance error code handling experience.

Author: Dominik Egert

 

Updated version available. Please see details on code base for further instructions. Also refer to documentation supplied in header file lib_error.mqh

 

From now on this project is part of MQLplus Library and shared via Shared Cloud Storage. You can find the current source files under "MQLplus" "MQLplus Include Library Collection".

To make use of the shared binary library as well as on how to use the code, see the Shared Cloud Storage Project "LibError" "MQLplus Enhanced Error Handler Library". it includes two files, one to compile the actual library to binary, and another to show its usage.

For those who need to compile the source into one ex4/5 file, all you need to do is remove the define-flag as show and documented in the HowTo-Project.


Also I welcome anyone to contribute to the code.

 
Hello author, how do I use the macro LIB_ERROR_IMPORT_SHARED_LIBRARY ? I defined the macro, but during runtime it shows an error message: cannot open file 'LibError.ex5'
 
  string str= "sss";
  int n = (int)str;
  SetMqlError(5040, "some output...");
  OnError();

What is the function of the second parameter of SetMqlError? Why don't I see its output, only the official default output

 
hini #:
Hello author, how do I use the macro LIB_ERROR_IMPORT_SHARED_LIBRARY ? I defined the macro, but during runtime it shows an error message: cannot open file 'LibError.ex5'

Because you first need to compile the actual shared library. You can do this with the attached file.

Place it into Libraries/LibError/* and compile it.

Then, in your project, you can use the shared library.

Files:
 
hini #:

What is the function of the second parameter of SetMqlError? Why don't I see its output, only the official default output

This is actually a "bug", I forgot to add the code for inserting the comment string.

In file lib_error_main.mqh at line 614, you will find this:

        { error_string = LIB_NAMESPACE(lib_err, func_ptr_mql_err_codes)(error_code); }


you will need to replace it with this:

        { error_string = ::StringFormat("%s %s", LIB_NAMESPACE(lib_err, func_ptr_mql_err_codes)(error_code), LIB_NAMESPACE(lib_err, err_desc_comment)()); }


I will update the code in the codebase when I find some time...