Let's go SetLastError!!!

 

GetLastError() will clear the special variable last_error. And so will hide all possible except expected if (GetLastError() == 4066) for example.

I want to use last_error itself, but it's invisible.

The _LastError() variable is not zeroed in MT5 GetLastError(). Thank goodness! ResetLastError() was invented for this!

And we have also added the SetUserError(user_error) function which numbers user errors in the following way:

_LastError = 65536 + user_error.

Obviously, one variable is used to store the last error, so it's essentially an unnecessary tweak.

You could just add SetLastError and that would be enough! Ideally just give last_error visibility.

An advanced programmer would understand himself how to number his errors, while all the rest GetLastError is more than enough.

I really miss this function in MT4, what should I do?

 
vit46:

GetLastError() will clear the special variable last_error. And so will hide all possible except expected if (GetLastError() == 4066) for example.

I want to use last_error itself, but it's invisible.

The _LastError() variable is not cleared in MT5 GetLastError(). Thank goodness! For this, ResetLastError() has been invented!

And we have also added the SetUserError(user_error) function which numbers user errors in the following way:

_LastError = 65536 + user_error.

Obviously, one variable is used to store the last error, so it's essentially an unnecessary tweak.

You could just add SetLastError and that would be enough! Ideally just give last_error visibility.

An advanced programmer would figure out how to number his errors himself, while all the rest GetLastError is more than enough.

I really miss this function in MT4, what should I do?

You can do without GetLastError().All possible errorsexcept the expected one will be hidden by an "advanced" programmer's crooked hands. Is there any special way of being "advanced" really necessary to save the error value into a variable and only then analyze it?
 
VladislavVG:
You can do without GetLastError().All possible errorsexcept the expected one will be hidden by an "advanced" programmer's crooked hands. Is there any special way of "advanced programming" really necessary to save the error value into a variable and only then analyze it?

Error handling is the very essence of programming. You underestimate something... I use many functions in one program in different files and I want to check one specific error in one function without nullifying possible other errors which may have occurred earlier in other functions in general... I already solved this problem actually... It wasn't so hard to replace the wretched GetLastError which clears what needs to be saved with two simple functions ....SetError and GetError ... but I would always have to switch them on...
 
vit46:

Error handling is the very essence of programming. You're underestimating something... I use many functions in one program in different files and I want check of one specific error in one function not to nullify possible other errors which may have occurred earlier in other functions... I already solved this problem actually... It wasn't so hard to replace the wretched GetLastError which clears what needs to be saved with two simple functions ....SetError and GetError ... but I have to always switch them on...

What prevents you from handling errors by place and time of occurrence rather than accumulating them? By the way, if you need to accumulate - make an array, fill it - then analyze it at the place you need. In both cases getLastError() will be enough.

As for the essence of programming, well done, thanks ......

 
Well, if you don't understand something, it's your problem :) Personally, I'm bored to provide for any case and insert GetLastError in any place where an error may occur. (And where else may it occur?) I write code as much as possible without errors. But there are some specific situations like error 4066 that may occur whenever I want and it does not depend on me. And I have to write handling code for such errors. But this evil GetLastError nulls all errors and they do not pass through the entire program. I check errors only once at the end, don't you see? Why do you think that MT5 has made it almost the way I want it? Probably because of my request :)
 
...and they also need exception handling, they can't live without it...
 
Integer:
...and they also need exception handling, they can't live without it...

and explicit type casting:)
 
vit46:
Personally, I'm bored to provide for any case and insert GetLastError in any place where an error may occur.

really, why would you do that?

The error should be handled as it occurs.

I understand that you write these constructs:

OrderSend(...);

if(GetLastError()> 0) { ... }

it's not right.

 

vit46:

Well, if you don't understand something, it's your problem :) Personally, I'm bored to provide for any case and insert GetLastError in any place where an error may occur. (And where else may it occur?) I write code as much as possible without errors. But there are some specific situations like error 4066 that may occur whenever I want and it does not depend on me. And I have to write handling code for such errors. But this evil GetLastError nulls all errors and they do not pass through the entire program. I check errors only once at the end, don't you see? Why do you think that MT5 has made it almost the way I want it? Probably because of my request :)

........
and explicit type conversion :)
:) I'll explain what you don't understand if hints don't come through: the advanced are advanced because they know how to use the opportunities provided.... If you don't have enough of the opportunities offered, write on the pluses. What's the problem?
 
VladislavVG:
:) Let me explain what you do not understand, since hints do not reach you: the advanced are advanced because they know how to use the opportunities provided.... If you do not have enough of the opportunities offered, write on the pluses. What is the problem?

I already wrote that I've solved this problem! It's a disadvantage of MQL4 language, it's easier to add a function to it... I'm not suggesting to change
 
sergeev:

really, why would you do that?

The error should be handled as it occurs.

I understand that you write these constructs:

OrderSend(...);

if (GetLastError()>0) { ... }

this is incorrect.



No I write like this:

OrderSend(...);

if (GetError()==конкретный номер){
         // код обработки сброс ошибки или наоборот
         SetError(0);
         }
else if(...)
...
...
// и в конце программы
if (GetError()) >0){
        // гдето необработанное исключение или ошибка номер...
        // просто сообщение об ошибке
        }
Reason: