You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Conor MacNeill <co...@m64.com> on 2000/01/19 15:49:53 UTC
[PATCH + NEW FILE] eliminate some of the "throws Exception" usage
Hi,
I have added a new exception class for Connector problems. Also attached are
a number of diffs to change over to using this exception.
src/share/org/apache/tomcat/core/ConnectorException.java
/*
* $Header$
* $Revision$
* $Date$
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.core;
/**
* Signals a problem in a ServerConnector
*
* @author Conor MacNeill [conor@m64.com]
*/
public class ConnectorException extends Exception {
private Throwable rootCause;
public ConnectorException() {
super();
}
public ConnectorException(String msg) {
super(msg);
}
/**
* Create a connector exception to encapsulate some underlying
exception.
*/
public ConnectorException(Throwable rootCause) {
super("Root cause - " + rootCause.getLocalizedMessage());
this.rootCause = rootCause;
}
/**
* Get the underlying exception that caused this ConnectorException.
*
* @return the <code>Throwable</code>
* that caused this connector exception
*/
public Throwable getRootCause() {
return rootCause;
}
}
Index: src/share/org/apache/tomcat/core/ContextManager.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManag
er.java,v
retrieving revision 1.23
diff -u -r1.23 ContextManager.java
--- ContextManager.java 2000/01/15 23:30:19 1.23
+++ ContextManager.java 2000/01/19 14:37:25
@@ -132,7 +132,7 @@
return contexts.keys();
}
- public void start() throws Exception {
+ public void start() throws ConnectorException {
// set a default connector ( http ) if none defined yet
if(connectors.size()==0) {
Index: src/share/org/apache/tomcat/core/ServerConnector.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/core/ServerConnec
tor.java,v
retrieving revision 1.1
diff -u -r1.1 ServerConnector.java
--- ServerConnector.java 1999/10/09 00:30:17 1.1
+++ ServerConnector.java 2000/01/19 14:37:25
@@ -70,9 +70,9 @@
public interface ServerConnector {
- public void start() throws Exception;
+ public void start() throws ConnectorException;
- public void stop() throws Exception;
+ public void stop() throws ConnectorException;
public void setContextManager( ContextManager ctx );
Index: src/share/org/apache/tomcat/service/TcpEndpointConnector.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpoi
ntConnector.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 TcpEndpointConnector.java
--- TcpEndpointConnector.java 1999/10/09 00:20:48 1.1.1.1
+++ TcpEndpointConnector.java 2000/01/19 14:37:26
@@ -112,18 +112,26 @@
ep=new TcpEndpoint();
}
- public void start() throws Exception {
- if( con==null) throw new Exception( "Invalid ConnectionHandler");
- con.setAttribute("context.manager",cm );
- ep.setPort(port);
- if( socketFactory != null) {
- ep.setServerSocketFactory( socketFactory );
- }
- ep.setConnectionHandler( con );
- ep.startEndpoint();
+ public void start() throws ConnectorException {
+ if( con==null) {
+ throw new ConnectorException( "Invalid ConnectionHandler");
+ }
+
+ try {
+ con.setAttribute("context.manager",cm );
+ ep.setPort(port);
+ if( socketFactory != null) {
+ ep.setServerSocketFactory( socketFactory );
+ }
+ ep.setConnectionHandler( con );
+ ep.startEndpoint();
+ }
+ catch (Exception e) {
+ throw new ConnectorException(e);
+ }
}
- public void stop() throws Exception {
+ public void stop() throws ConnectorException {
ep.stopEndpoint();
}
Index: src/share/org/apache/tomcat/service/http/HttpAdapter.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/http/Http
Adapter.java,v
retrieving revision 1.4
diff -u -r1.4 HttpAdapter.java
--- HttpAdapter.java 2000/01/15 23:30:25 1.4
+++ HttpAdapter.java 2000/01/19 14:37:27
@@ -99,16 +99,24 @@
ep.setConnectionHandler( con );
}
- public void start() throws Exception {
- if( con==null) throw new Exception( "Invalid ConnectionHandler");
- ep.setPort(vport);
- if( socketFactory != null) {
- ep.setServerSocketFactory( socketFactory );
+ public void start() throws ConnectorException {
+ if( con==null) {
+ throw new ConnectorException( "Invalid ConnectionHandler");
}
- ep.startEndpoint();
+
+ try {
+ ep.setPort(vport);
+ if( socketFactory != null) {
+ ep.setServerSocketFactory( socketFactory );
+ }
+ ep.startEndpoint();
+ }
+ catch (Exception e) {
+ throw new ConnectorException(e);
+ }
}
- public void stop() throws Exception {
+ public void stop() throws ConnectorException {
ep.stopEndpoint();
}
--
Conor MacNeill
conor@m64.com
M64 Pty Limited
Re: [PATCH + NEW FILE] eliminate some of the "throws Exception"usage
Posted by Hans Bergsten <ha...@gefionsoftware.com>.
costin@costin.dnt.ro wrote:
>
> Please wait a bit with this patch.
> - what about using TomcatException instead of ConnectorException ?
> ( it will also be used by Interceptors, and probably other internal
> components). ( Servlet API doesn't define a new exception for
> every possible error case, and I don't think we should do that
> either. I wouldn't mind just using ServletException. )
TomcatException should be okay, but please don't use ServletException.
ServletException is defined as an exception thrown by servlets, period.
Throwing the same exception for internal container problems would be
very misleading.
Hans
--
Hans Bergsten hans@gefionsoftware.com
Gefion Software http://www.gefionsoftware.com
Re: [PATCH + NEW FILE] eliminate some of the "throws Exception"
usage
Posted by co...@costin.dnt.ro.
Please wait a bit with this patch.
- what about using TomcatException instead of ConnectorException ?
( it will also be used by Interceptors, and probably other internal
components). ( Servlet API doesn't define a new exception for
every possible error case, and I don't think we should do that
either. I wouldn't mind just using ServletException. )
Costin
> I have added a new exception class for Connector problems. Also attached are
> a number of diffs to change over to using this exception.
>
> src/share/org/apache/tomcat/core/ConnectorException.java
Re: [PATCH + NEW FILE] eliminate some of the "throws Exception"
usage
Posted by co...@eng.sun.com.
On Thu, 20 Jan 2000, Conor MacNeill wrote:
> Hi,
>
> I have added a new exception class for Connector problems. Also attached are
> a number of diffs to change over to using this exception.
>
> src/share/org/apache/tomcat/core/ConnectorException.java
>
> /*
> * $Header$
> * $Revision$
> * $Date$
> *
> * ====================================================================
> *
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 1999 The Apache Software Foundation. All rights
> * reserved.
> *
> * Redistribution and use in source and binary forms, with or without
> * modification, are permitted provided that the following conditions
> * are met:
> *
> * 1. Redistributions of source code must retain the above copyright
> * notice, this list of conditions and the following disclaimer.
> *
> * 2. Redistributions in binary form must reproduce the above copyright
> * notice, this list of conditions and the following disclaimer in
> * the documentation and/or other materials provided with the
> * distribution.
> *
> * 3. The end-user documentation included with the redistribution, if
> * any, must include the following acknowlegement:
> * "This product includes software developed by the
> * Apache Software Foundation (http://www.apache.org/)."
> * Alternately, this acknowlegement may appear in the software itself,
> * if and wherever such third-party acknowlegements normally appear.
> *
> * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
> * Foundation" must not be used to endorse or promote products derived
> * from this software without prior written permission. For written
> * permission, please contact apache@apache.org.
> *
> * 5. Products derived from this software may not be called "Apache"
> * nor may "Apache" appear in their names without prior written
> * permission of the Apache Group.
> *
> * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> * SUCH DAMAGE.
> * ====================================================================
> *
> * This software consists of voluntary contributions made by many
> * individuals on behalf of the Apache Software Foundation. For more
> * information on the Apache Software Foundation, please see
> * <http://www.apache.org/>.
> *
> * [Additional notices, if required by prior licensing conditions]
> *
> */
>
>
> package org.apache.tomcat.core;
>
> /**
> * Signals a problem in a ServerConnector
> *
> * @author Conor MacNeill [conor@m64.com]
> */
>
> public class ConnectorException extends Exception {
>
> private Throwable rootCause;
>
> public ConnectorException() {
> super();
> }
>
> public ConnectorException(String msg) {
> super(msg);
> }
>
> /**
> * Create a connector exception to encapsulate some underlying
> exception.
> */
> public ConnectorException(Throwable rootCause) {
> super("Root cause - " + rootCause.getLocalizedMessage());
> this.rootCause = rootCause;
> }
>
> /**
> * Get the underlying exception that caused this ConnectorException.
> *
> * @return the <code>Throwable</code>
> * that caused this connector exception
> */
> public Throwable getRootCause() {
> return rootCause;
> }
> }
>
> Index: src/share/org/apache/tomcat/core/ContextManager.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManag
> er.java,v
> retrieving revision 1.23
> diff -u -r1.23 ContextManager.java
> --- ContextManager.java 2000/01/15 23:30:19 1.23
> +++ ContextManager.java 2000/01/19 14:37:25
> @@ -132,7 +132,7 @@
> return contexts.keys();
> }
>
> - public void start() throws Exception {
> + public void start() throws ConnectorException {
>
> // set a default connector ( http ) if none defined yet
> if(connectors.size()==0) {
> Index: src/share/org/apache/tomcat/core/ServerConnector.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/core/ServerConnec
> tor.java,v
> retrieving revision 1.1
> diff -u -r1.1 ServerConnector.java
> --- ServerConnector.java 1999/10/09 00:30:17 1.1
> +++ ServerConnector.java 2000/01/19 14:37:25
> @@ -70,9 +70,9 @@
>
> public interface ServerConnector {
>
> - public void start() throws Exception;
> + public void start() throws ConnectorException;
>
> - public void stop() throws Exception;
> + public void stop() throws ConnectorException;
>
> public void setContextManager( ContextManager ctx );
>
> Index: src/share/org/apache/tomcat/service/TcpEndpointConnector.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpoi
> ntConnector.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 TcpEndpointConnector.java
> --- TcpEndpointConnector.java 1999/10/09 00:20:48 1.1.1.1
> +++ TcpEndpointConnector.java 2000/01/19 14:37:26
> @@ -112,18 +112,26 @@
> ep=new TcpEndpoint();
> }
>
> - public void start() throws Exception {
> - if( con==null) throw new Exception( "Invalid ConnectionHandler");
> - con.setAttribute("context.manager",cm );
> - ep.setPort(port);
> - if( socketFactory != null) {
> - ep.setServerSocketFactory( socketFactory );
> - }
> - ep.setConnectionHandler( con );
> - ep.startEndpoint();
> + public void start() throws ConnectorException {
> + if( con==null) {
> + throw new ConnectorException( "Invalid ConnectionHandler");
> + }
> +
> + try {
> + con.setAttribute("context.manager",cm );
> + ep.setPort(port);
> + if( socketFactory != null) {
> + ep.setServerSocketFactory( socketFactory );
> + }
> + ep.setConnectionHandler( con );
> + ep.startEndpoint();
> + }
> + catch (Exception e) {
> + throw new ConnectorException(e);
> + }
> }
>
> - public void stop() throws Exception {
> + public void stop() throws ConnectorException {
> ep.stopEndpoint();
> }
>
> Index: src/share/org/apache/tomcat/service/http/HttpAdapter.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/http/Http
> Adapter.java,v
> retrieving revision 1.4
> diff -u -r1.4 HttpAdapter.java
> --- HttpAdapter.java 2000/01/15 23:30:25 1.4
> +++ HttpAdapter.java 2000/01/19 14:37:27
> @@ -99,16 +99,24 @@
> ep.setConnectionHandler( con );
> }
>
> - public void start() throws Exception {
> - if( con==null) throw new Exception( "Invalid ConnectionHandler");
> - ep.setPort(vport);
> - if( socketFactory != null) {
> - ep.setServerSocketFactory( socketFactory );
> + public void start() throws ConnectorException {
> + if( con==null) {
> + throw new ConnectorException( "Invalid ConnectionHandler");
> }
> - ep.startEndpoint();
> +
> + try {
> + ep.setPort(vport);
> + if( socketFactory != null) {
> + ep.setServerSocketFactory( socketFactory );
> + }
> + ep.startEndpoint();
> + }
> + catch (Exception e) {
> + throw new ConnectorException(e);
> + }
> }
>
> - public void stop() throws Exception {
> + public void stop() throws ConnectorException {
> ep.stopEndpoint();
> }
>
>
> --
> Conor MacNeill
> conor@m64.com
> M64 Pty Limited
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>