GetLastError() vs. _LastError

To add comments, please log in or register
parham.trader
669
parham.trader  

Hi friends,

I'm going to show the lasterror both on the terminal using the Print function and export it to the file.

First I used GetLastError() on the Print function and then again use it on the procedure of exporting it on the file when I found out that the GetLastError return zero on my file and as I read the documentation I found out the _LastError reset after first using of GetLastError().

Now I'm considering the use of _LastError instead of GetLastError() on both Print function and exporting the error code on the file. Is there any deficiency on using the _LastError compared to GetLastError() ?

I know there is another solution such as setting a variable equal to GetLastError() and then use that variable anywhere else I want, But my main issue is about the differences between _lastError and GetLastError().

Thanking in advance for your kind guidance,

Alain Verleyen
38685
Alain Verleyen  
parham.trader:

Hi friends,

I'm going to show the lasterror both on the terminal using the Print function and export it to the file.

First I used GetLastError() on the Print function and then again use it on the procedure of exporting it on the file when I found out that the GetLastError return zero on my file and as I read the documentation I found out the _LastError reset after first using of GetLastError().

Now I'm considering the use of _LastError instead of GetLastError() on both Print function and exporting the error code on the file. Is there any deficiency on using the _LastError compared to GetLastError() ?

I know there is another solution such as setting a variable equal to GetLastError() and then use that variable anywhere else I want, But my main issue is about the differences between _lastError and GetLastError().

Thanking in advance for your kind guidance,

No problem using it. Only difference if the function reset the error after returning the value (which is NOT the case with mql5).
William Roeder
20214
William Roeder  
parham.trader: But my main issue is about the differences between _lastError and GetLastError().
  1. You already know the difference, GLE clears _LastError.
  2. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
To add comments, please log in or register