GetLastError

Returns the contents of the system variable _LastError.

int  GetLastError();

Return Value

Returns the value of the last error that occurred during the execution of an mql5 program.

Note

After the function call, the contents of _LastError are not reset. To reset this variable, you need to call ResetLastError().

Example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   MqlRates rates[1]={};   // display the current bar data here
   
//--- intentionally call a function with inappropriate parameters
   int res=CopyRates(NULLPERIOD_CURRENT02rates);
   if(res!=2)
      PrintFormat("CopyRates() returned %d. LastError %d"resGetLastError());
 
//--- reset the last error code before copying the current bar data to the MqlRates structure
   ResetLastError();
//--- if the function does not work correctly, the error code will differ from 0
   CopyRates(NULLPERIOD_CURRENT01rates);
   Print("CopyRates() error "GetLastError());
     
//--- print the array of obtained values
   ArrayPrint(rates);
  }

See also

Trade Server Return Codes