• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to throw exceptipn through servlet.

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are throwing an exception & catching it back...
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dont use try catch ..just throw the exception..
 
Ranch Hand
Posts: 45
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic