You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/09/02 13:11:16 UTC

cvs commit: ws-jaxme/src/api/javax/xml/bind JAXBException.java

jochen      2004/09/02 04:11:15

  Modified:    src/api/javax/xml/bind JAXBException.java
  Log:
  Improved readability of Exceptions.
  
  Revision  Changes    Path
  1.5       +34 -9     ws-jaxme/src/api/javax/xml/bind/JAXBException.java
  
  Index: JAXBException.java
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/api/javax/xml/bind/JAXBException.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JAXBException.java	23 Jul 2004 06:46:59 -0000	1.4
  +++ JAXBException.java	2 Sep 2004 11:11:15 -0000	1.5
  @@ -38,15 +38,38 @@
       public JAXBException(String pMessage) {
           super(pMessage);
       }
  -    
  +
  +    private static String formatMessage(String pErrorCode, String pMessage, Throwable pThr) {
  +    	String msg = null;
  +        if (pMessage == null) {
  +            if (pThr != null) {
  +            	msg = pThr.getMessage();
  +                if (msg == null) {
  +                	msg = pThr.getClass().getName();
  +                }
  +            }
  +        } else {
  +        	msg = pMessage;
  +        }
  +        if (pErrorCode == null) {
  +        	return msg;
  +        } else {
  +            if (msg == null) {
  +            	return pErrorCode;
  +            } else {
  +            	return pErrorCode + ": " + msg;
  +            }
  +        }
  +        
  +    }
  +
       /** <p>Creates a new <code>JAXBException</code> with the specified
        * detail message and vendor specific error code.</p>
        * @param pMessage The detail message.
        * @param pErrorCode The error code.
        */
       public JAXBException(String pMessage, String pErrorCode) {
  -        super(pMessage);
  -        errorCode = pErrorCode;
  +        this(pMessage, pErrorCode, null);
       }
       
       /** <p>Creates a new <code>JAXBException</code> with the specified
  @@ -54,8 +77,7 @@
        * @param pLinkedException The linked exception.
        */
       public JAXBException(Throwable pLinkedException) {
  -        super(pLinkedException.getMessage() == null ? pLinkedException.getClass().getName() : pLinkedException.getMessage());
  -        linkedException = pLinkedException;
  +        this(null, null, pLinkedException);
       }
       
       /** <p>Creates a new <code>JAXBException</code> with the specified
  @@ -64,8 +86,7 @@
        * @param pLinkedException The linked exception.
        */
       public JAXBException(String pMessage, Throwable pLinkedException) {
  -        super(pMessage);
  -        linkedException = pLinkedException;
  +        this(pMessage, null, pLinkedException);
       }
       
       /** <p>Creates a new <code>JAXBException</code> with the specified
  @@ -76,7 +97,7 @@
        */
       public JAXBException(String pMessage, String pErrorCode,
   						 Throwable pLinkedException) {
  -        super(pMessage);
  +        super(formatMessage(pErrorCode, pMessage, pLinkedException));
           errorCode = pErrorCode;
           linkedException = pLinkedException;
       }
  @@ -111,7 +132,11 @@
               return errorCode + ": " + super.toString();
           }
       }
  -    
  +
  +    public void printStackTrace() {
  +        printStackTrace(System.err);
  +    }
  +
       public void printStackTrace(PrintStream pStream) {
           super.printStackTrace(pStream);
           Throwable t = getLinkedException();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org