Let's go SetLastError!!! - page 2

 
vit46:


No I write it this way:


in this case it's wrong too.

you see that each function returns false or -1 if it fails.

that's what you use.

int ticket=OrderSend();
if (ticket<0) // и только после этого
{  GetLastError()  }
 
vit46:

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

The GetLastError() function is reset after you read its value. Insert an extra blank read before the operation you want.

int err=GetLastError();
OrderSend(...);

if (GetError()==конкретный номер){
         // код обработки сброс ошибки или наоборот
         SetError(0);
         }
else if(...)
 
sergeev:

in this case it's wrong too.

you see that each function returns false or -1 if it fails.

that's what you should use.


That's really right! I didn't even think of that... because there is an even better way, like me :) I can write complex functions that generate their own error codes.
 
Roger:

The GetLastError() function is reset after reading its value. Insert an additional empty read before the operation you want.


That's the thing, I don't want to put a read before the required operation every time... I have all the operations I need, so I have to do GetLastError on the line:)
 
vit46:

That's the thing: I don't want to put a read before the required operation every time... I have all the operations I need, so I have to do GetLastError on the line:)

Then it's not clear how you would like your new function to work. How it could update itself by time or any other signs?
 
I would like to read and write a special variable last_error. Handled the error, set to zero - not handled - the error code reaches the end of the program and is detected there.
 
vit46:


No I write it this way:

OrderSend(...);

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

No offence - this is also wrong.

It is the operation error that needs to be monitored: that is, what OrderSend (...) returns and only then, if necessary, call GetLastError().

 
Everyone goes crazy in their own way, it's only the flu that gets everybody together. (Prostokvashino)
 
VladislavVG:


That's right, it works as intended :) But no offense, I looked through your codes, I didn't find any call to GetLastError()... The first fly that flies through the window will destroy civilization :)
 
vit46:

That's right, it works as intended :) But no offense, I looked through your codes, I didn't find any call to GetLastError() ... The first fly that flies through the window will destroy civilization :)
And look where I wrote about error handling - there are forum threads ;)