Let's go SetLastError!!! - page 4

 
sergeev:

You still haven't written how your suggestion will help improve MQL. so far it's just bare requests, which only you need, with an unclear purpose.

I already wrote in the beginning that MQL5 has that effect, while in MQL4 it can be improved by giving last_error visibility. Once again, I've solved the problem for the second time with two homemade functions. It's not last_error but rather first last error plus possibility of custom error codes as in MQL5.
 
Roger:

This is not good, because if you had an error from a previous operation and did not handle it, then if there is no error in the current operation, you will handle the previous one.

Yes everything is ok if you do not call GetLastError but only from a function that returns a fake error and has already changed the code of a possible previous error to a new one!
 
vit46:

Yes, everything is fine if you do not call GetLastError but only from a function that returns a fake error and has already changed the code of a possible previous error to a new one!

By checking the error in an additional function, you just null it. However, if you have code places where you don't check for an error but it might occur, you may run into an inappropriate error.
 
Roger:

By checking the error in the additional function, you are clearing it.


No, I am not clearing it:

// глобально видимая переменная для всей программы
int last_error_fifo = 0;

int GetError()
   {
   if (last_error_fifo == 0)
      {
      last_error_fifo = GetLastError();
      }
   return(last_error_fifo);
   }

void SetError(int errcode)
   {
   last_error_fifo = errcode;
   // Это можно делать и напрямую, но только установку ошибки или сброс.
   // Для чтения ошибки только GetError() иначе GetLastError не сработает.
   }
 

Can anyone recommend the Most Decent (in your opinion) error handling function?

 
charter:

Can anyone recommend the Most Decent (in your opinion) error handling function?


There's not much to choose ... make it with what you've got... or don't make an unconditional call to GetLastError
 
vit46:


No, I don't reset it:


What is this?

last_error_fifo = GetLastError();
 
vit46:

It's not really a choice ... make do with what we've got... or not to make an unconditional call to GetLastError

No, I'm not talking about the error information, I'm talking about the "correct behaviour" of the EA when an error occurs/detects an error.
 
Roger:


What's this?


It's not unconditional zeroing but only if last_error_fifo == 0. In short, it's the same as eggs in profile. check what the function returned before checking for errors.
 
charter:

No, I'm not talking about the error information, I'm talking about the 'correct behaviour' of the EA when an error occurs/detects an error.

It depends on your logic. After all, you can handle every error, and you can only handle the ones that are important in a given situation.
Reason: