Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to write/delete a file couple of times per minute. I have try/catch inside code but my strategy keeps getting stopped with the following error:
The strategy runs couple of days, then suddenly shuts down
can anyone spot what is the issue here? Been trying for couple of months to figure it out. It usually stop at elsystem.io.StreamWriter.Create step. The file it tried to create could be accessed by other software.
BUT - the MAIN question here is why Try Catch not working? it just avoids it and stops the strategy, Really getting crazy here
Thank You
Can you help answer these questions from other members on NexusFi?
Very generically I can tell you that you are hitting a null value error. So you need to check and make sure your variable / object is not null before you call it.
For example this throws an error:
double testvariable = 0;
testvariable = null;
if (testvarialbe > 1)
{
// do something
}
So you have to check if it is null first before you evaluate it.
I am not sure where you are hitting your error in your code:
"Error:elsystem.NullObjectException: Object Reference not set to an instance of an object." But whatever line is throwing this error, just check your variable to make sure it is not null and you should be fine.
Happy Coding!
Ian
In the analytical world there is no such thing as art, there is only the science you know and the science you don't know. Characterizing the science you don't know as "art" is a fools game.
did you post the entire method code? What happens if you place your method call inside a try catch statement, without trying to catch a specific exception?
try
myf_writetofile() ; //your method in here
catch (elsystem.exception ex)
Print("ex = " + ex.ToString());
end ;
Regards,
ABCTG
eronyx
Hi guys
I am trying to write/delete a file couple of times per minute. I have try/catch inside code but my strategy keeps getting stopped with the following error:
Error:elsystem.NullObjectException: Object Reference not set to an instance of an object. Call Stack: MyStrat.myf_writetofile()
The strategy runs couple of days, then suddenly shuts down
can anyone spot what is the issue here? Been trying for couple of months to figure it out. It usually stop at elsystem.io.StreamWriter.Create step. The file it tried to create could be accessed by other software.
BUT - the MAIN question here is why Try Catch not working? it just avoids it and stops the strategy, Really getting crazy here
Try
Begin
file = elsystem.io.StreamWriter.Create("C:\........\Files\Final.csv");
End;
Catch (elsystem.NullObjectException ex) Begin
Print(" File Create +" + ex.ToString()+" MSG: "+ex.Message.ToString()+" Type "+ex.InnerException.ToString());
End;
Catch (elsystem.io.IOException ex1) Begin
Print(" File Create IO Except +" + ex1.ToString()+" MSG: "+ex1.Message.ToString()+" Type "+ex1.InnerException.ToString());
End;
End;
Try Begin
file.Write(NewGDtoFile);
End;
Catch (elsystem.NullObjectException ex) Begin
Print(" File Write +" + ex.ToString()+" MSG: "+ex.Message.ToString()+" Type "+ex.InnerException.ToString());
End;
Catch (elsystem.io.IOException ex1) Begin
Print(" File Write IO Except +" + ex1.ToString()+" MSG: "+ex1.Message.ToString()+" Type "+ex1.InnerException.ToString());
End;
End;
Try Begin
file.Close();
End;
Catch (elsystem.NullObjectException ex) Begin
Print(" File Close NULL +" + ex.ToString()+" MSG: "+ex.Message.ToString()+" Type "+ex.InnerException.ToString());
End;
Catch (elsystem.io.IOException ex1) Begin
Print(" File Close IO Except " + ex1.ToString()+" MSG: "+ex1.Message.ToString()+" Type "+ex1.InnerException.ToString());
End;
End;
BUT - the MAIN question here is why Try Catch not working? it just avoids it and stops the strategy, Really getting crazy here
Hi eronyx,
the error is most likely not caused due to the try statement failing here, but due to ex.InnerException or ex1.InnerException causing the error in your print statement. When you check the below code, you will find it raises a similar error message:
Removing ex.InnerException from the print will result in the code getting executed without the error message i.e. the DivideByZeroException getting caught and the print out to appear. The same is probably true for your code, too.
The fix for your code should be to check that the InnerException is not null before you print it. So something along the lines of
it's like at some point it can't delete/create file again and gives this error, then works fine 3-5 days(writing this file few times per minute) then again stops here.
I am not even able to do the if (file> 1) as you suggested or something because it stops right there.
iantg
Very generically I can tell you that you are hitting a null value error. So you need to check and make sure your variable / object is not null before you call it.
For example this throws an error:
double testvariable = 0;
testvariable = null;
if (testvarialbe > 1)
{
// do something
}
So you have to check if it is null first before you evaluate it.
I am not sure where you are hitting your error in your code:
"Error:elsystem.NullObjectException: Object Reference not set to an instance of an object." But whatever line is throwing this error, just check your variable to make sure it is not null and you should be fine.
Thank You ABCTG, that indeed could be issue, is like it is not stopping at the try catch, but at that print method alone.
tricky tricky. Good catch !!!
Thanks again, I will also try placing the entire method in try catch if this does not work.
ABCTG
Hi eronyx,
the error is most likely not caused due to the try statement failing here, but due to ex.InnerException or ex1.InnerException causing the error in your print statement. When you check the below code, you will find it raises a similar error message: