Try/Catch Method Challenge/Mistery - futures io
futures io



Try/Catch Method Challenge/Mistery


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one eronyx with 3 posts (0 thanks)
    2. looks_two ABCTG with 2 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 iantg with 1 posts (1 thanks)
    1. trending_up 1,072 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Try/Catch Method Challenge/Mistery

(login for full post details)
  #1 (permalink)
eronyx
Moldova
 
 
Posts: 9 since Nov 2017
Thanks: 6 given, 0 received

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:

 
Code
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

 
Code
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;
Thank You

Reply With Quote

Can you help answer these questions
from other members on futures io?
For the experts of Metastock
Platforms and Indicators
TD Sequential for NT or MW?
Platforms and Indicators
Is there inherently more opportunity in smaller markets?
Traders Hideout
Experience with AGN (Introducing Broker)
Brokers
1 min chart v-shape scan help please
ThinkOrSwim
 
 
(login for full post details)
  #3 (permalink)
 iantg 
charlotte nc
 
Experience: Master
Platform: ninjatrader
Broker: NinjaTrader
Trading: Emini (ES, YM, NQ, ect.)
 
Posts: 399 since Jan 2015
Thanks: 81 given, 1,093 received


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








eronyx View Post
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:

 
Code
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

 
Code
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;
Thank You


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.
Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to iantg for this post:
 
(login for full post details)
  #4 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,264 since Apr 2013
Thanks: 417 given, 1,509 received

eronyx,

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?
 
Code
try
 myf_writetofile() ; //your method in here
catch (elsystem.exception ex)
   Print("ex = " + ex.ToString());
end ;
Regards,

ABCTG




eronyx View Post
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:

 
Code
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

 
Code
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;
Thank You


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #5 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,264 since Apr 2013
Thanks: 417 given, 1,509 received


eronyx View Post
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:

 
Code
once
begin
	try
  	
  	Value2 = 2 ;
  	Value3 = 1 ;
  	
  	Value1 = 1 / ( Value2 - Value3 - 1 ) ;
	
	catch (elsystem.exception ex)
		Print( "ex = " + ex.ToString() + "; ex.Message = " + ex.Message + "; InnerException = ", ex.InnerException.ToString() ) ;
	end ;
end ;
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
 
Code
if ex.InnerException <> null then
	Print( "ex = " + ex.ToString() + "; ex.Message = " + ex.Message + "; InnerException = " + ex.InnerException.ToString() ) 
else
	Print( "ex = " + ex.ToString() + "; ex.Message = " + ex.Message + "; InnerException = null" ) ;
should prevent the error.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #6 (permalink)
eronyx
Moldova
 
 
Posts: 9 since Nov 2017
Thanks: 6 given, 0 received

This is the line where it stops

file = elsystem.io.StreamWriter.Create("C:\........\Files\Final.csv");

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 View Post
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


Reply With Quote
 
(login for full post details)
  #7 (permalink)
eronyx
Moldova
 
 
Posts: 9 since Nov 2017
Thanks: 6 given, 0 received

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 View Post
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:

Regards,

ABCTG


Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Try/Catch Method Challenge/Mistery


Last Updated on July 18, 2018


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

August
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts