
This library uses short descriptive texts for each of the errors present in the MQL5 Reference. It will be updated frequently as new errors are constantly added to the official documentation
Last Update: 2024-02-29
Usage Example:
(Don't forget to copy the fileErrorDescription2.mq5 to the folder \MetaTrader 5\MQL5\Include)
//+------------------------------------------------------------------+
//| test.mq5 |
//| Copyright 2024, Paulo Henrique |
//| https://www.mql5.com/en/users/pau1ohenrique.dev |
//+------------------------------------------------------------------+
#propertycopyright"Copyright 2024, Paulo Henrique"
#propertylink"https://www.mql5.com/en/users/pau1ohenrique.dev"
#propertyversion"1.00"
// Includes
#include <ErrorDescription2.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
voidOnStart()
{
//--- usage example #1
Print("Description of MQL5 errors:");
for(inti=FIRST_RUNTIME_ERROR; i<=LAST_TRADE_SERVER_ERROR; i++)
{
stringerror_desc=GetError(i);
if(IsSuccess(i) || error_desc==NULL)
continue;
if(IsRuntimeError(i))
Print("RuntimeError: ",error_desc);
if(IsTradeServerError(i))
Print("TradeServerError: ",error_desc);
if(IsUserError(i))
Print("UserError: ",error_desc);
}
//--- usage example #2
Print("\nLast error description:");
intretcode=GetLastError();
if(!IsSuccess(retcode))
Print(GetError(retcode));
//--- or simply
Print(GetError());
// The operation completed successfully [0]
// Unexpected internal error [4001]
// ...
Print(GetError(false));
// The operation completed successfully
// Unexpected internal error
// ...
}
//+------------------------------------------------------------------+
I will soon publish a library with a class that simplifies the use of errors in MQL5, including simplifying user error reporting using a Raise(my_error) method for example.