Avatar of Loganathan Natarajan
Loganathan NatarajanFlag for India asked on

how do I handle the null pointer exception on my web pages?

In my web application, I use struts and hibernate .., some times, the null pointer exceptions are occuring and it displays the error something like this, see the attached image ...

i want to redirect to some error message page instead of showing this messages ... i know the null pointer exception could be handled well on the Try .. .Catch loop to do


error.JPG
Java

Avatar of undefined
Last Comment
Loganathan Natarajan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
krishna kishore mellacheruvu venkata

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
humanonomics

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Loganathan Natarajan

@melchkishore ... any sample work?

@ humanonomics ... looks good, i will try this...
krishna kishore mellacheruvu venkata

in UserManager.java
verifyUserLogin method will throw Exception

try
{
..........   business logic.............
} catch(Exception e)
{
    throw new Exception(<key>,<Message>)
}

Action class
try
{
         .........business logic............
} catch(Exception e)
{
    if (e instanceOf NullPointerException)
{
       ActionErrors actionErrors = new ActionErrors();
     actionErrors.add("nullPointer",new ActionError("error.null");
    request.setAttribute(ERROR,actionErrors);

}
}

In jsp
<html:errors/>

Please find the sample code. let me know if u have any concerns.
ASKER
Loganathan Natarajan

thanks .... this is good,  i will try and get back to you all ...

thanks guys ...
Your help has saved me hundreds of hours of internet surfing.
fblack61