Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Public Firebird Java API.
   *
   * 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 name of the author may not be used to endorse or promote products 
  *       derived from this software without specific prior written permission.
  * 
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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.
  */
 
 package org.firebirdsql.gds;

A GDS-specific exception

Author(s):
David Jencks
Roman Rokytskyy
 
 public class GDSException extends Exception {
 
     private static final long serialVersionUID = -2993273656432230359L;
     
     private final int type;
     private final int intParam;
     private final String strParam;

    
The variable xaErrorCode is used to allow the same code to be used for transaction control from the XAResource, LocalTransaction, and Connection. This code may be added to the GDSException without obscuring the message: only at the final level is the GDSException converted to the spec-required exception.
 
     private int xaErrorCode;

    
My child
 
     private GDSException next;

    
Factory method to create a new instance with a given XA error code.

Parameters:
message Message for the new instance
xaErrorCode The XA error code
 
     public static GDSException createWithXAErrorCode(String messageint xaErrorCode) {
         GDSException gdse = new GDSException(message);
         gdse.setXAErrorCode(xaErrorCode);
         return gdse;
     }

    
Create a new instance.

Parameters:
type type of the exception, should be always ISCConstants.isc_arg_gds, otherwise no message will be displayed.
intParam Additional int parameter about the new exception
 
     public GDSException(int typeint intParam) {
         this. = type;
         this. = intParam;
         this. = null;
     }

    
Create a new instance.

Parameters:
type type of the exception, should be always ISCConstants.isc_arg_gds, otherwise no message will be displayed.
strParam value of the string parameter that will substitute {0} entry in error message corresponding to the specified error code.
 
     public GDSException(int typeString strParam) {
         this. = type;
         this. = strParam;
         this. = 0;
     }
    
    
Construct instance of this class. This method correctly constructs chain of exceptions for one string parameter.

Parameters:
type type of the exception, should be always ISCConstants.isc_arg_gds, otherwise no message will be displayed.
fbErrorCode Firebird error code, one of the constants declared in GDS interface.
strParam value of the string parameter that will substitute {0} entry in error message corresponding to the specified error code.
    public GDSException(int typeint fbErrorCodeString strParam) {
        this. = type;
        this. = fbErrorCode;
        this. = null;
        setNext(new GDSException(.strParam));
    }
    
    
Construct instance of this class. This method correctly constructs chain of exceptions for one string parameter.

Parameters:
type type of the exception, should be always ISCConstants.isc_arg_gds, otherwise no message will be displayed.
fbErrorCode Firebird error code, one of the constants declared in GDS interface.
strParam value of the string parameter that will substitute {0} entry in error message corresponding to the specified error code.
cause Cause of this exception
    public GDSException(int typeint fbErrorCodeString strParamThrowable cause) {
        this(typefbErrorCodestrParam);
        initCause(cause);
        setNext(new GDSException(.strParam));
    }

    
Create a new instance.

Parameters:
fbErrorCode Firebird error code, one of the constants declared in GDS interface
    public GDSException(int fbErrorCode) {
        this. = fbErrorCode;
        this. = .;
        this. = null;
    }
    
    
Create a new instance.

Parameters:
fbErrorCode Firebird error code, one of the constants declared in GDS interface
cause Cause of this exception
    public GDSException(int fbErrorCodeThrowable cause) {
        this(fbErrorCode);
        initCause(cause);
    }

    
Create a new instance with only a simple message.

Parameters:
message Message for the new exception
    public GDSException(String message) {
        super(message);
        this. = .;
        this. = 0;
        this. = null;
    }

    
Get the Firebird-specific error code for this exception.

Returns:
The Firebird error code
    public int getFbErrorCode() {
        switch () {
        case .:
        case .:
            return ;
        default:
            return -1;
        }
    }
    
    
Get the SQL state of this exception.

Returns:
the SQL state of this exception or null if this object does not represent an error.
    public String getSQLState() {
        switch () {
        case .:
        case .:
            return GDSExceptionHelper.getSQLState();
        default:
            return null;
        }
    }

    
Get the int parameter for this exception.

Returns:
The int parameter
    public int getIntParam() {
        return ;
    }


    
Get the XaErrorCode value.

Returns:
the XaErrorCode value.
    public int getXAErrorCode() {
        return ;
    }

    
Set the XaErrorCode value.

Parameters:
xaErrorCode The new XaErrorCode value.
    public void setXAErrorCode(int xaErrorCode) {
        this. = xaErrorCode;
    }

    
Set the next exception in the chain.

Parameters:
e The next chained exception
    public void setNext(GDSException e) {
         = e;
    }

    
Get the next chained exception.

Returns:
The next chained exception
    public GDSException getNext() {
        return ;
    }
    
    
Retrieve whether this exception is a warning.

Returns:
true if this is a warning, false otherwise
    public boolean isWarning() {
        return  == .;
    }

    
Returns a string representation of this exception.
    public String getMessage() {
        String msg;
        
        GDSException child = this.;
        
        // If I represent a GDSMessage code, then let's format it nicely.
        if ( == . ||  == .) {
            // get message
            GDSExceptionHelper.GDSMessage message =
                GDSExceptionHelper.getMessage();
            // substitute parameters using my children
            int paramCount = message.getParamCount();
            for(int i = 0; i < paramCounti++) {
                if (child == nullbreak;
                message.setParameter(ichild.getParam());
                child = child.next;
            }
            // convert message to string
            msg = message.toString();
        }
        else {
            // No GDSMessage code, so use the default message.
            msg = super.getMessage();
        }
  
        // Do we have more children? Then include their messages too.
        if (child != null) {
            msg += "\n" + child.getMessage();
        }
 
        return msg;
    }

    
Returns the parameter depending on the type of the error code.
    public String getParam() {
        switch () {
        case .:
        case .:
            return ;
        case .:
            return String.valueOf();
        default:
            return "";
        }
    }
New to GrepCode? Check out our FAQ X