Standard Errors

30 March 2018, 11:31
Ziheng Zhuang
3
33

The mqh library includes two functions for obtaining error information.

  • string ErrorDescription(int code)  : the function returns the description of error code.
  • string ErrorConstant(int code)  :    the function returns the string of the enum constant.
//+------------------------------------------------------------------+
//|                                           test_standarderros.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <StandardErrors.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

void OnStart()
  {
//---
   int code; //=GetLastError();
   code=10010;
   printf("error code = %d, description = %s",code,ErrorDescription(code));
   printf("error code = %d, constant string = %s",code,ErrorConstant(code));

   SetUserError(100);
   code=GetLastError();

   Print("error code =",code,"  ---  ",ErrorDescription(code));
   Print("error code =",code,"  ---  ",ErrorConstant(code));
  }
//+------------------------------------------------------------------+
//test result:
//error code = 10010, description = Only part of the request was completed
//error code = 10010, constant string = TRADE_RETCODE_DONE_PARTIAL
//error code =65636  ---  User error 100
//error code =65636  ---  USER ERROR 100

Trade error from trade server:  

https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes

Runtime error:

https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes

Share it with friends: