[英]How to use a MetaTrader4 Error Code Refresh for proper error handling?
I have a "set up" on my EA to ping me an email when my Expert Advisor experiences an error and provides me the error code in accordance with the pre-determined 3-4 digit error code in the documentation on the MQL4 website .我的 EA 上有一个“设置”,当我的“EA 交易”遇到错误时,它会向我发送一封电子邮件,并根据MQL4 网站上的文档中预先确定的 3-4 位错误代码向我提供错误代码。
/* technically speaking,
error codes with 5+ digits are also possible,
Using:
------ */
SetUserError( 1000000 ); /*
// this will set an error-state
// with a number 1065536 -- having a bit more than the said 3 ~ 4 digits
// composed as ( 1000000 + ERR_USER_ERROR_FIRST )
*/
This is to enable me to diagnose the problem.这是为了让我能够诊断问题。
Just wanting to clarify if I need to refresh the error code ( from a previous error ) I'm getting in my email, or does it do this automatically, when a new error is presented in the Journal of my MT4 Platform?只是想澄清一下我是否需要刷新我收到的电子邮件中的错误代码(来自之前的错误),还是在我的 MT4 平台日志中出现新错误时自动执行此操作?
There is a helpful function ResetLastError()
that explicitly sets _LastError
to zero.有一个有用的函数
ResetLastError()
明确地将_LastError
设置为零。 Next, there is also a side effect of each call to a GetLastError()
function, as it also sets zero to the _LastError
variable.接下来,每次调用
GetLastError()
函数也会产生副作用,因为它还_LastError
变量设置为零。
Either way, it is a common practice to embed ( surround ) a section, where some error-states need to get handled accordingly, right by a:无论哪种方式,嵌入(环绕)一个部分是一种常见的做法,其中一些错误状态需要得到相应的处理,正确的是:
// -------------------------------------------- // START_________________________
GetLastError(); // implicit pre-reset _LastError
ResetLastError(); // explicit pre-reset _LastError
bool an_OK_flag = OrderModify( ... ); // XTO call w ex-post _LastError
int anErrorSTATEtoHANDLE = GetLastError(); /* get a value of the _LastError
+ implicit post-reset _LastError */
// -------------------------------------------- // HANDLE ERROR-STATE(s)
switch( anErrorSTATEtoHANDLE ){
case ERR_NO_ERROR: break;
case ERR_NO_RESULT: ...
break;
case ERR_INVALID_TRADE_PARAMETERS: ...
break;
case ERR_SERVER_BUSY: ...
break;
case ERR_BROKER_BUSY: ...
break;
case ERR_TOO_MANY_REQUESTS: ...
break;
case ERR_TRADE_MODIFY_DENIED: ...
break;
...
default: break;
}
// -------------------------------------------- // FIN __________________________
This makes your code robust against any kind of some "forgotten" ( coincidentally un-reset ) last error ( which was not crashing your code-execution at the place, where such error has appeared but ... ) which would trigger later an unwanted behaviour in the "next" error-handling section, thus potentially sending you an email also in cases, where the email-signal was not present, but the "forgotten" ( un-reset ) value inside the _LastError
system register co-incidentally matched the error-handling case, resulting in sending the said email ( as if there were an email-signal present ( which was not, as described above ).这使您的代码能够抵抗任何类型的“遗忘”(巧合地未重置)最后一个错误(这不会在出现此类错误的地方使您的代码执行崩溃,但是......)这将在以后触发一个不需要的“下一个”错误处理部分中的行为,因此在不存在电子邮件信号但
_LastError
系统寄存器中的“忘记”(未重置)值偶然匹配的情况下,也可能向您发送电子邮件错误处理情况,导致发送所述电子邮件(好像存在电子邮件信号(如上所述)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.