How to avoid zero divide error in runtime ?

 

any standard procedures for that.

is there any way to reload an ea automatically when it exits due to certain errors ?

i am not using arrays or any indicator related items.

 

nope so make sure it does not happen.

check the value before you divide and if it's 0 change it.

 
balachandran chandrasekar:

any standard procedures for that.

is there any way to reload an ea automatically when it exits due to certain errors ?

i am not using arrays or any indicator related items.

Your approach could be done with try & catch.
But never ends good...

I don't know what you are trying to do, but do you know this functionality?

double variable = 0.0;
double division = 1000.0 / ( variable == 0.0 ? 1.0 : 0.0 ) ; 

That would avoid the runtime error but not sure what you are trying to accomplish

 

Like Marco said, test it for zero before the process where you might be dividing by zero.

(not tested code, just to show example)

if (valueYouDontWantToBeZero = 0)
{
   // do this code
}
else
{
   // do this code that lets you divide by that value
}
 
JD4:

Like Marco said, test it for zero before the process where you might be dividing by zero.

(not tested code, just to show example)

if (valueYouDontWantToBeZero = 0)
{
   // do this code
}
else
{
   // do this code that lets you divide by that value 

} 

Slight correction:

 

if (valueYouDontWantToBeZero == 0)
 
Both work, depends on how complicated you want to get if it does = zero.  For me, I like to see it broken down further.
 
JD4:
Both work, depends on how complicated you want to get if it does = zero.  For me, I like to see it broken down further.
No sory, they don't both work. "=" is assigning a value, "==" is a comparison operator
 
Stuart Browne:
No sory, they don't both work. "=" is assigning a value, "==" is a comparison operator
Ah, I see it now, good catch, thought you were trying to condense the entire if/else down to one line.  My mistake.
 
Marco vd Heijden:

nope so make sure it does not happen.

check the value before you divide and if it's 0 change it.

My total code length runs beyond 27000+ lines.

Defending every division is going to be a very long task. 

 
JD4:
Ah, I see it now, good catch, thought you were trying to condense the entire if/else down to one line.  My mistake.
No worries ;-)
 
balachandran chandrasekar:

My total code length runs beyond 27000+ lines.

Defending every division is going to be a very long task. 

27000? Nice work!

It's a pain but shouldn't be too bad if you wrap the checking code in a function, pass in the numerator and denominator and return the result
Reason: