throw exceptions


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: throw exceptions

  1. #1
    tyris Guest

    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


  2. #2
    Rajkamal Gopinath Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center