Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Libraries | ErrorDescription - Updated library

Photo for the article ErrorDescription - Updated library

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.



    48431

    Best MetaTrader Indicators + Profitable Expert Advisors