akarasulu 2003/11/02 10:38:13
Modified: merlin/util/env/src/java/org/apache/avalon/util/env Env.java
EnvAccessException.java
Log:
Exception handling improvements
Revision Changes Path
1.3 +10 -10
avalon/merlin/util/env/src/java/org/apache/avalon/util/env/Env.java
Index: Env.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/util/env/src/java/org/apache/avalon/util/env/Env.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Env.java 2 Nov 2003 18:29:11 -0000 1.2
+++ Env.java 2 Nov 2003 18:38:13 -0000 1.3
@@ -199,7 +199,7 @@
return getWindowsShellVariables() ;
}
- throw new EnvAccessException( "NA",
+ throw new EnvAccessException(
new UnsupportedOperationException( "Environment operations not "
+ "supported on unrecognized operatings system" ) ) ;
}
@@ -224,7 +224,7 @@
return getWindowsUserShell() ;
}
- throw new EnvAccessException( "NA",
+ throw new EnvAccessException(
new UnsupportedOperationException( "Environment operations not "
+ "supported on unrecognized operatings system" ) ) ;
}
@@ -271,7 +271,7 @@
if ( l_index == -1 )
{
- throw new EnvAccessException( "NA",
+ throw new EnvAccessException(
"/etc/passwd contains malformed user entry for "
+ USERNAME ) ;
}
@@ -282,14 +282,14 @@
}
catch ( IOException e )
{
- throw new EnvAccessException( "NA", e ) ;
+ throw new EnvAccessException( e ) ;
}
- throw new EnvAccessException( "NA", "User " + USERNAME
+ throw new EnvAccessException( "User " + USERNAME
+ " does not seem to exist in /etc/passwd" ) ;
}
- throw new EnvAccessException( "NA", "Don't know what to do with"
+ throw new EnvAccessException( "Don't know what to do with"
+ " a UNIX system without a readable /etc/passwd file" ) ;
}
@@ -458,7 +458,7 @@
// Check that we exited normally before returning an invalid output
if ( 0 != l_proc.exitValue() )
{
- throw new EnvAccessException( "NA", "Environment process failed "
+ throw new EnvAccessException( "Environment process failed "
+ " with non-zero exit code of " + l_proc.exitValue() ) ;
}
@@ -544,7 +544,7 @@
catch( Throwable t )
{
t.printStackTrace() ;
- throw new EnvAccessException( "ALL", t ) ;
+ throw new EnvAccessException( t ) ;
}
finally
{
@@ -565,7 +565,7 @@
if ( 0 != l_proc.exitValue() )
{
- throw new EnvAccessException( "ALL", "Environment process failed"
+ throw new EnvAccessException( "Environment process failed"
+ " with non-zero exit code of " + l_proc.exitValue() ) ;
}
1.2 +40 -6
avalon/merlin/util/env/src/java/org/apache/avalon/util/env/EnvAccessException.java
Index: EnvAccessException.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/util/env/src/java/org/apache/avalon/util/env/EnvAccessException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnvAccessException.java 2 Nov 2003 16:57:00 -0000 1.1
+++ EnvAccessException.java 2 Nov 2003 18:38:13 -0000 1.2
@@ -48,7 +48,8 @@
*/
-package org.apache.avalon.util.env;
+package org.apache.avalon.util.env ;
+
/**
* A simple wrapper exception around exceptions that could occur while accessing
@@ -62,8 +63,40 @@
{
/** the environment variable name if available */
public final String m_variable ;
+ /** root cause */
+ public final Throwable m_cause ;
- public final Throwable m_cause;
+ /**
+ * Creates an exception denoting a failure while attempting to access an
+ * environment variable within an operating system and shell specific
+ * environment that is caused by another exception.
+ *
+ * @param a_cause the underlying exception that caused the failure
+ */
+ EnvAccessException( final Throwable a_cause )
+ {
+ super() ;
+
+ m_variable = null ;
+ m_cause = a_cause ;
+ }
+
+
+ /**
+ * Creates an exception denoting a failure while attempting to access an
+ * environment variable within an operating system and shell specific
+ * environment.
+ *
+ * @param a_message the reason for the access failure
+ */
+ EnvAccessException( final String a_message )
+ {
+ super( a_message ) ;
+
+ m_variable = null ;
+ m_cause = null ;
+ }
+
/**
* Creates an exception denoting a failure while attempting to access an
@@ -71,7 +104,6 @@
* environment that is caused by another exception.
*
* @param a_variable the variable whose value was to be accessed
- * @param a_message the reason for the access failure
* @param a_cause the underlying exception that caused the failure
*/
EnvAccessException( final String a_variable, final Throwable a_cause )
@@ -79,7 +111,7 @@
super() ;
m_variable = a_variable ;
- m_cause = a_cause;
+ m_cause = a_cause ;
}
@@ -110,6 +142,7 @@
return m_variable ;
}
+
/**
* Return the causal exception.
*
@@ -117,9 +150,10 @@
*/
public Throwable getCause()
{
- return m_cause;
+ return m_cause ;
}
+
/**
* Prepends variable name to the base message.
*
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]