throw Exception
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   tyris_d
Posted On:   Friday, June 1, 2001 04:52 AM

hi all, i'm new to java language and i'd like to know : i have made a progam where i throw java.lang.NullPointerException this way : public StringBuffer search(String SQLstring, StringBuffer sb_DATA) throws java.lang.NullPointerException { try { ..... } catch (NullPointerException d) { System.out.println("error : " + d + " "); d.printStackTrace(); } } the problem is that when a NullPointerException exist, i do have this result : error : java.lang.NullPointerException and nothing else (i mean i don't know where in my code is the error) is there a way to know   More>>

hi all,


i'm new to java language and i'd like to know :


i have made a progam where i throw java.lang.NullPointerException this way :

			
public StringBuffer search(String SQLstring, StringBuffer sb_DATA) throws java.lang.NullPointerException {
try
{
.....
}
catch (NullPointerException d)
{
System.out.println("error : " + d + "
");
d.printStackTrace();
}
}

the problem is that when a NullPointerException exist, i do have this result :
			
error : java.lang.NullPointerException

and nothing else (i mean i don't know where in my code is the error)


is there a way to know which code part is the reason of the error ?    <<Less

Re: throw Exception

Posted By:   Simon_Ablett  
Posted On:   Thursday, June 28, 2001 07:24 AM

Just a small point. Why are you declaring that your search method will throw null pointer exception when you are catching them and not rethrowing ?

I note that you also do not have a return statement at the end (to return a string buffer object). Maybe a fuller listing of your code would help track down the problem. Is it possible that you are acting on an object whose reference might be null outside of the try block's scope ?

Re: throw Exception

Posted By:   Tim_Rohaly  
Posted On:   Friday, June 1, 2001 10:51 AM

printStackTrace() prints the line number to
standard error (see the API documentation). Perhaps
whatever environment you are working in
(are you using an IDE?)
is capturing your output to standard error.
Note that the Java VM will print out a stack trace
automatically in event of an uncaught runtime exception -
you don't have to put in the code yourself (i.e. try/catch and print
out the trace).


A NullPointerException occurs when
you are trying to invoke a method on a null object reference -
you are probably declaring an object and trying to use it
without creating it first (can't tell, since you don't provide
the relevant code). Maybe one of your input parameters
is a null...

About | Sitemap | Contact