Forums Register Login

How to throw exceptipn through servlet.

+Pie Number of slices to send: Send
I am writing a new servlet, which gets the app as input parameter if it null then throw a exception with custom message. I am trying to do but not successful.
Here is the my code snippet.




On the web page it display: You have the access...

but I want to display PARAMETER NULL EXCEPTION. if app is null

but it's not happening.

Could anybody help me.

Thanks.
+Pie Number of slices to send: Send
 

On the web page it display: You have the access...

but I want to display PARAMETER NULL EXCEPTION. if app is null



This means that reg != null
so the code didn't even run the try/catch block because it didn't pass the (if reg == null) test



Now, I would like to know what does this line of code print in the console, obviously it printed something since it is failing the (if reg == null)
test.

what I have typed so far really hasn't help with your issue, what's is the url to get to the "You have access..." page? that should tell you if the app request parameter is passing something to the servlet. One final thought is under what kind of condition that your app request parameter will be null, if you can recreate that than you should be able to see the exception
+Pie Number of slices to send: Send
You are throwing an exception & catching it back...
+Pie Number of slices to send: Send
Dont use try catch ..just throw the exception..
+Pie Number of slices to send: Send
You are straightway catching the thrown exception.Moving the throw clause into catch block will help as it will help you to catch the other exceptions and throw the NullPointer one.
+Pie Number of slices to send: Send
You should not be catching exceptions in the servlets. Define an error handler in the web.xml and let it handle all exceptions -- and not by just silently eating them either.
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1337 times.
Similar Threads
Upload/download file
Form Variables
Why is instanceof considered harmful?
InstantiationException
compatibility of date format
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:56:36.