gt:         this(logwriter, msgid, new Object[] { arg1, arg2, arg3 });
context: /*
   * Apache Derby is a subproject of the Apache DB project, and is licensed under
   * the Apache License, Version 2.0 (the "License"); you may not use these files
   * except in compliance with the License. You may obtain a copy of the License at:
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software distributed
   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
   * specific language governing permissions and limitations under the License.
   *
   * Splice Machine, Inc. has modified this file.
   *
   * All Splice Machine modifications are Copyright 2012 - 2020 Splice Machine, Inc.,
   * and are licensed to you under the License; you may not use this file except in
   * compliance with the License.
   *
   * Unless required by applicable law or agreed to in writing, software distributed
   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
   * specific language governing permissions and limitations under the License.
   *
   */
  
  package com.splicemachine.db.client.am;
  
  import java.sql.SQLException;
  
  import com.splicemachine.db.shared.common.i18n.MessageUtil;
  import com.splicemachine.db.shared.common.error.ExceptionUtil;
  import com.splicemachine.db.shared.common.reference.MessageId;
  import com.splicemachine.db.shared.common.reference.SQLState;
  
  
  // The signature of the stored procedure SQLCAMessage I have come out so far is as follows:
  // SQLCAMessage (
  //     IN  SQLCode       INTEGER,
  //     IN  SQLErrml      SMALLINT,
  //     IN  SQLErrmc      VARCHAR(70),
  //     IN  SQLErrp       CHAR(8),
  //     IN  SQLErrd0      INTEGER,
  //     IN  SQLErrd1      INTEGER,
  //     IN  SQLErrd2      INTEGER,
  //     IN  SQLErrd3      INTEGER,
  //     IN  SQLErrd4      INTEGER,
  //     IN  SQLErrd5      INTEGER,
  //     IN  SQLWarn       CHAR(11),
  //     IN  SQLState      CHAR(5),
  //     IN  Locale        CHAR(5),
  //     IN  BufferSize    SMALLINT,
  //     IN  LineWidth     SMALLINT,
  //     OUT Message       VARCHAR(2400))
  //
  // Some issues have been identified:
  // 1. What would be the schema name of the stored procedue SQLCAMessage?
  // 2. What is the format and type of the Locale parameter? If there does, I would really like to know the format of the locale in order to decide the type of the Locale parameter. Even there does not either, the Locale parameter probably still needs to be kept there for future extension, and we need to figure out the format of the locale.
  // 3. What would be the format of the output message? Is this full message text ok or do we only need the explanation message corresponding to an SQL code. This somehow matters whether we need the Buffersize and Linewidth parameters for the stored procedure.
  // 4. What if the invocation of stored procedure failed (due to, eg, connection dropping)? In this case, we probably need to return some client-side message.
  //
  // Note that this class does NOT extend java.sql.SQLException.  This is because
  // in JDBC 4 there will be multiple subclasses of SQLException defined by the
  // spec.  So we can't also extend SQLException without having to create our
  // own mirror hierarchy of subclasses.
  //
  // When Derby is ready to throw an exception to the application, it catches
  // SqlException and converts it to a java.sql.SQLException by calling the
  // method getSQLException.
  //
  // It is also possible that internal routines may call public methods.
  // In these cases, it will need to wrap a java.sql.SQLException inside
  // a Derby SqlException so that the internal method does not have to throw
  // java.sql.SQLException.  Otherwise the chain of dependencies would quickly
  // force the majority of internal methods to throw java.sql.SQLException.
  // You can wrap a java.sql.SQLException inside a SqlException by using
  // the constructor <code>new SqlException(java.sql.SQLException wrapMe)</code)
  //
  public class SqlException extends Exception implements Diagnosable {
      protected static final int DEFAULT_ERRCODE = 99999;
      protected transient Sqlca sqlca_ = null; // for engine generated errors only
      /** Tells which of the messages in the SQLCA this exception refers to
       * (counting from 0). For engine generated errors only. */
      private transient int messageNumber_;
      protected String message_ = null;
      protected String cachedMessage_ = null;
      private String batchPositionLabel_; // for batched exceptions only
      protected String sqlstate_ = null;
      protected int errorcode_ = DEFAULT_ERRCODE;
      protected String causeString_ = null;
      protected SqlException nextException_;
      protected Throwable throwable_;
      
      public static final String CLIENT_MESSAGE_RESOURCE_NAME =
          "com.splicemachine.db.loc.clientmessages";
      
      //SQLException factory initialised with default factory
      //It will be over written by the SQLException factory of the 
      //supported jdbc version    
      protected static SQLExceptionFactory 
              exceptionFactory = new SQLExceptionFactory ();
      
      /** 
       *  The message utility instance we use to find messages
       *  It's primed with the name of the client message bundle so that
       *  it knows to look there if the message isn't found in the
       *  shared message bundle.
       */
      private static MessageUtil msgutil_;
      
      /**
       * This routine provides singleton access to an instance of MessageUtil
       * that is constructed for client messages.  It is recommended to use
       * this singleton rather than create your own instance.
       *
       * The only time you need this instance is if you need to directly
       * format an internationalized message string.  In most instances this
       * is done for you when you invoke a SqlException constructor
       *
       * @return a singleton instance of MessageUtil configured for client
       *   messages
       */
      public static MessageUtil getMessageUtil() {
          if ( msgutil_ == null ) {
              msgutil_ = new MessageUtil(CLIENT_MESSAGE_RESOURCE_NAME);
          }
          
          return msgutil_;
      }
  
      /** 
       * The wrapped SQLException, if one exists
       */
      protected SQLException wrappedException_;
    
      //-----------------constructors-----------------------------------------------
      // New constructors that support internationalized messages
      // The message id is wrapped inside a class so that we can distinguish
      // between the signatures of the new constructors and the old constructors
      
      /**
       * Create a SqlException.  This constructor is the "base" constructor;
       * all other constructors (which take a ClientMessageId) delegate to this
       * constructor
       *
       * @param logwriter
       *      Can be null, but if provided, it is used to log this exception
       *
       * @param msgid
       *      The message id for this message.  ClientMessageId is a simple type-safe
       *      wrapper for com.splicemachine.db.shared.common.reference.SQLState message id
       *      strings.
       *
       * @param args
       *      The set of substitution arguments for the message.  The Java message
       *      formatter will substitute these arguments into the internationalized
       *      strings using the substitution ({0}, {1}, etc.) markers in the string.
       *      Any object can be passed, but if you want it to be readable, make sure
       *      toString() for the object returns something useful.
       *
       * @param cause
       *      Can be null.  Indicates the cause of this exception.  If this is
       *      an instance of SqlException or java.sql.SQLException then the exception
       *      is chained into the nextException chain.  Otherwise it is chained
       *      using initCause().  On JDK 1.3, since initCause() does not exist,
       *      a non-SQL exception can not be chained.  Instead, the exception class
       *      and message text is appended to the message for this exception.
       */
      public SqlException(LogWriter logwriter, 
          ClientMessageId msgid, Object[] args, Throwable cause)
      {
          this(
              logwriter,
              cause,
              getMessageUtil().getCompleteMessage(
                  msgid.msgid,
                  args),
              ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
              ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));        
      }
  
      // Use the following SQLExceptions when you want to override the error
      // code that is derived from the severity of the message id.
      public SqlException(LogWriter logWriter, ClientMessageId msgid, Object[] args,
          SqlCode sqlcode, Throwable t) {
          this(logWriter, msgid, args, t);
          this.errorcode_ = sqlcode.getCode();
      }
  
      public SqlException(LogWriter logWriter, ClientMessageId msgid, Object[] args,
          SqlCode sqlcode) {
          this(logWriter, msgid, args, sqlcode, (Throwable)null);
      }
          
      public SqlException(LogWriter logWriter, ClientMessageId msgid, SqlCode sqlcode) {
          this(logWriter, msgid, (Object[])null, sqlcode);
      }
      
      public SqlException(LogWriter logWriter, ClientMessageId msgid, Object arg1,
          SqlCode sqlcode) {
          this(logWriter, msgid, new Object[] {arg1}, sqlcode);
      }
          
      public SqlException(LogWriter logWriter, ClientMessageId msgid, Object arg1,
          Object arg2, SqlCode sqlcode) {
          this(logWriter, msgid, new Object[] {arg1, arg2}, sqlcode);
      }
   
      // The following constructors are all wrappers around the base constructor,
      // created to make it easy to code against them (you don't have to pass
      // null arguments or construct object arrays).  See the javadoc for the
      // "base" constructor for an explanation of the parameters
      public SqlException (LogWriter logwriter, 
              ClientMessageId msgid, Throwable cause) {
          this (logwriter, msgid, (Object[])null, cause);
      }
      
      public SqlException(LogWriter logwriter, ClientMessageId msgid, Object[] args)
      {
          this(logwriter, msgid, args, (Throwable)null);
      }
      
      public SqlException (LogWriter logwriter, ClientMessageId msgid)
      {
          this(logwriter, msgid, (Object[])null);
      }
      
      public SqlException(LogWriter logwriter, ClientMessageId msgid, Object arg1)
      {
          this(logwriter, msgid, new Object[] { arg1 });
      }
      
      public SqlException(LogWriter logwriter, ClientMessageId msgid, 
              Object arg1, Throwable cause)
      {
          this(logwriter, msgid, new Object[] { arg1 }, cause);
      }
      
      public SqlException(LogWriter logwriter, ClientMessageId msgid,
          Object arg1, Object arg2, Throwable cause)
      {
          this(logwriter, msgid, new Object[] { arg1, arg2 }, cause);
      }
      
      public SqlException(LogWriter logwriter,
          ClientMessageId msgid, Object arg1, Object arg2)
      {
          this(logwriter, msgid, new Object[] { arg1, arg2 });
      }
      
      public SqlException(LogWriter logwriter,
          ClientMessageId msgid, Object arg1, Object arg2, Object arg3)
      {
  