MT5 not throwing zero divide error

 

The following script code throws zero divide error(experts tab) in MT4 but not in MT5. Is this normal behavior or a bug.

void OnStart(void)
  {
   double   div   =  0.0;
   
   double   res   =  10/div;
   
   Print(res);
  }
 

What value is returned in "res"?

On mine it prints "inf". This probably means that in MQL5 instead of throwing an error, it produces a valid mathematical value of "infinity", probably a Positive Infinity.

 
It is possible to disable zero dev in the project options of mql5.

Maybe you have disabled that?
 
Dominik Christian Egert #: It is possible to disable zero dev in the project options of mql5. Maybe you have disabled that?

Oh? That I did not know? I don't use project files, so its no wonder.

Is it possible to control that with a compilation directive instead of a project file?

Actually, when I tested the OP's code I did a normal compile (not as a project), and it do not throw a zero divide either. It gave an "inf" result as reported in my previous post.

Could this be due to the latest MT5 build?

 
Fernando Carreiro #:

What value is returned in "res"?

On mine it prints "inf". This probably means that in MQL5 instead of throwing an error, it produces a valid mathematical value of "infinity", probably a Positive Infinity.

Yes it does prints that but I was wondering why not just throw error, display in tab and stop the program like in MT4.

 
Dominik Christian Egert #:
It is possible to disable zero dev in the project options of mql5.

Maybe you have disabled that?

You mean when we use (.proj) files but this is not from a project file and I have never used the project option before.

 

In MT5 it does produce the error in tab when an integer value is used for division.

void OnStart(void)
  {
   int   div   =  0;
   
   double   res   =  10/div;
   
   Print(res);
  }