aspose file tools*
The moose likes Servlets and the fly likes How to throw exceptipn through servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to throw exceptipn through servlet." Watch "How to throw exceptipn through servlet." New topic
Author

How to throw exceptipn through servlet.

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 203
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.
Davie Lin
Ranch Hand

Joined: Aug 05, 2007
Posts: 294
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
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
You are throwing an exception & catching it back...
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
Dont use try catch ..just throw the exception..


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Smitesh Shinde
Ranch Hand

Joined: Feb 16, 2008
Posts: 45

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to throw exceptipn through servlet.
 
Similar Threads
Upload/download file
Form Variables
Why is instanceof considered harmful?
InstantiationException
compatibility of date format