-
throw exceptions
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 + "\n");
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 ?
Best regards ,
Elise
-
Re: throw exceptions
Hi
1) remove throws NullPointerException in the first line, because its not
needed when you handle it by using try and catch.
2) Remove d.printStackTrace() from your code , since you need to know in
which line you have the error, rather than which method in the whole application
which caused the error
3) Insert System.println() in every line with some different messages and
execute it...
you will find the error easily
Regards
Rajkamal
"tyris" <kea@mailcity.com> wrote:
>
>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 + "\n");
> }
>}
>
>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 ?
>Best regards ,
>Elise
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks