You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Raphael <rc...@alphacent.com> on 2002/05/02 13:49:58 UTC

How to add a throw exception to a servlet

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The doPost method of a servlet looks like this :

public class selectdetail extends HttpServlet {
    public void doPost(HttpServletRequest request,
		       HttpServletResponse response)
	throws ServletException, IOException {

What if in my doPost method I am using Object methods that throw other 
exceptions, like SQLException. The Java compiler would not let me write :

public void doPost(HttpServletRequest request,
		       HttpServletResponse response)
	throws ServletException, IOException,SQLException

But I want the exception to be caught in the error.jsp page, not do a try 
{...} catch{...} inside the doPost body.

I don't know if I explained it correctly but is there a simple solution to 
this problem ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE80Sfrh2ITK4xBkFERAgMfAJ95HwnlLTICnfOeOrK33jifllqhtACdFrXN
xtFJ/YRjwGEqQNESeKRTrAE=
=IMF1
-----END PGP SIGNATURE-----


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: How to add a throw exception to a servlet

Posted by Raphael <rc...@alphacent.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm late with this reply but thanks!

Le Vendredi 03 Mai 2002 12:26, Ion Larranaga a écrit :
> Hi,
>
> There's no way to add new exception types to the doPost method. However,
> you could do something like:
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException
> {
> 	try
> 	{
> 		/*
> 		your code
> 		*/
> 	}
> 	catch (SQLException exc)
> 	{
> 		throw new ServletException(exc);
> 	}
> }
>
> This way, the real exception goes nested within a ServletException and you
> don't have to change the method signature.
>
> Hope it helps,
>
>    Ion
>
> >But I want the exception to be caught in the error.jsp page, not do a try
> >{...} catch{...} inside the doPost body.
> >
> >I don't know if I explained it correctly but is there a simple solution to
> >this problem ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE814m1h2ITK4xBkFERAstoAJ9ZvhkOi5ndsMuzBDssBIPGl48lNACfRxXg
qDjJ8zUzIyi28j+iMMJBsJs=
=K4I9
-----END PGP SIGNATURE-----


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to add a throw exception to a servlet

Posted by Ion Larranaga <il...@s21sec.com>.
Hi,

There's no way to add new exception types to the doPost method. However,
you could do something like:

public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException
{
	try
	{
		/*
		your code
		*/
	}
	catch (SQLException exc)
	{
		throw new ServletException(exc);
	}
}

This way, the real exception goes nested within a ServletException and you
don't have to change the method signature.

Hope it helps,

   Ion



>But I want the exception to be caught in the error.jsp page, not do a try
>{...} catch{...} inside the doPost body.
>
>I don't know if I explained it correctly but is there a simple solution to
>this problem ?


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: How to add a throw exception to a servlet

Posted by Chetan Wagle <ch...@capstoneit.com>.
Hi Raphel,

    Can you let me know why you have this peculiar requirement of 
changing the signature of the doPost method ?

Rgds,
Chetan

___________________________________________________________________________
 
Chetan Wagle
Project Manager
Capstone IT Technologies Pvt. Ltd.
 
www.capstoneit.com

TeleFax: +91 (0)40 6786951
Email  : chetan.wagle@capstoneit.com
___________________________________________________________________________


Legally privileged/Confidential Information may be contained in this 
message. If you are not the addressee(s) legally indicated in this message 
(or responsible for delivery of the message to such person), you may not
copy or deliver this message to anyone. In such case, you should destroy 
this message, and notify us immediately. If you or your employer does not 
consent to Internet e-mail messages of this kind, please advise us 
immediately. Opinions, conclusions and other information expressed in this 
message are not given or endorsed by my firm or employer unless otherwise 
indicated by an authorised representative independent of this message. 
Please note that despite using the latest virus software, neither my 
employer nor I accept any responsibility for viruses and it is your 
responsibility to scan attachments (if any).
 

Raphael wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>The doPost method of a servlet looks like this :
>
>public class selectdetail extends HttpServlet {
>    public void doPost(HttpServletRequest request,
>		       HttpServletResponse response)
>	throws ServletException, IOException {
>
>What if in my doPost method I am using Object methods that throw other 
>exceptions, like SQLException. The Java compiler would not let me write :
>
>public void doPost(HttpServletRequest request,
>		       HttpServletResponse response)
>	throws ServletException, IOException,SQLException
>
>But I want the exception to be caught in the error.jsp page, not do a try 
>{...} catch{...} inside the doPost body.
>
>I don't know if I explained it correctly but is there a simple solution to 
>this problem ?
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: For info see http://www.gnupg.org
>
>iD8DBQE80Sfrh2ITK4xBkFERAgMfAJ95HwnlLTICnfOeOrK33jifllqhtACdFrXN
>xtFJ/YRjwGEqQNESeKRTrAE=
>=IMF1
>-----END PGP SIGNATURE-----
>
>
>--
>To unsubscribe:   <ma...@jakarta.apache.org>
>For additional commands: <ma...@jakarta.apache.org>
>Troubles with the list: <ma...@jakarta.apache.org>
>
>
>

-- 


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>