Esempio n. 1
0
        /*
        ** Name: createProviderException
        **
        ** Description:
        **	Create an IngresException from the SqlEx exception
        **	using the IngresExceptionFactory interface.
        **
        ** Input:
        **	this.
        **
        ** Ouptut:
        **	None.
        **
        ** Returns:
        **	IngresException	    The exception object.
        **
        ** History:
        **	24-Feb-04 (thoda04)
        **	    Created.
        **	20-Aug-09 (thoda04)
        **	    Trap SecurityException if running with less than
        **	    FullTrust and user application does not have
        **	    EnvironmentPermission=Unrestricted.  Fixes Bug 122511.
        */

        /// <summary>
        /// Create an IngresException from an SqlEx exception.
        /// </summary>
        /// <returns>An IngresException.</returns>
        internal Exception createProviderException()
        {
            Exception innerException;
            string    callStack;

            while ((innerException = this.getNextException()) != null)
            {
                if (!(innerException is SqlEx)) // look for a non-SqlEx
                {
                    break;                      // and use it as the InnerException
                }
            }
            exCursor = 0;              // reset the exlist cursor

            try
            {
                callStack = Environment.StackTrace;

                // find and strip the frames prior to the current stack frame
                int i = callStack.IndexOf("createProviderException");
                if (i > -1)                                        // should not happen
                {
                    i = callStack.IndexOf(Environment.NewLine, i); // find end
                }
                if (i > -1)                                        // should not happen
                {
                    i = callStack.IndexOf(Environment.NewLine,
                                          i + Environment.NewLine.Length);        // find end of one more
                }
                if (i > -1)
                {
                    callStack = callStack.Substring(i);                      // strip prior and current
                }
            }
            catch (SecurityException)
            {
                // System.Environment.StackTrace required
                //    EnvironmentPermission=Unrestricted
                callStack = String.Empty;
            }


            Exception providerEx =              // create an IngresException
                                   providerExFactory.CreateInstance(
                this.Message,
                this.getSQLState(),
                this.getErrorCode(),
                innerException,
                this.StackTrace + callStack);

            Exception ex;

            while ((ex = this.getNextException()) != null)
            {
                // look for all SqlEx and append them as error records
                SqlEx sqlEx = ex as SqlEx;
                if (sqlEx != null)
                {
                    // add new error messages to existing IngresException
                    providerExFactory.AddError(
                        providerEx,
                        sqlEx.Message,
                        sqlEx.getSQLState(),
                        sqlEx.getErrorCode());
                }
            }

            return(providerEx);
        }