Convert an Exception into an unchecked exception. Return the exception if it is
already an unchecked exception or return an ExceptionConverter wrapper otherwise

@param ex the exception to convert
@return an unchecked exception
@since 2.1.6
161797
public static final RuntimeException convertException(Exception ex) {
        if (ex instanceof RuntimeException) {
            return (RuntimeException) ex;
        }
        return new ExceptionConverter(ex);
    }
1110417
public static Throwable findExceptionCause( Throwable e )
  {
    Throwable error = e;
    Throwable cause = e;
    while( (error.getCause() != null) && (error.getCause() != error) )
    {
      cause = error.getCause();
      error = cause;
    }
    return cause;
  }
427787
public DatabaseException convertError(Exception ex)
    {
        DatabaseException eDB = null;
        int iError = DBConstants.ERROR_RETURN;
        String strMessage = "Error!";
        if (ex != null)
            strMessage = ex.getMessage();
        if (ex instanceof SQLException)
        {
            SQLException sqlex = (SQLException)ex;
            String strState = sqlex.getSQLState();
            strMessage += strState;
            if (!m_bFirstErrorCheck)
            {
                m_bFirstErrorCheck = true;
                m_strFileNotFoundErrorText = (String)this.getProperties().get(SQLParams.TABLE_NOT_FOUND_ERROR_TEXT);
                if (m_strFileNotFoundErrorText != null)
                    m_strFileNotFoundErrorText = m_strFileNotFoundErrorText.toLowerCase();
                m_strFileNotFoundErrorCode = (String)this.getProperties().get(SQLParams.TABLE_NOT_FOUND_ERROR_CODE);
                m_strDBNotFoundErrorText = (String)this.getProperties().get(SQLParams.DB_NOT_FOUND_ERROR_TEXT);
                if (m_strDBNotFoundErrorText != null)
                    m_strDBNotFoundErrorText = m_strDBNotFoundErrorText.toLowerCase();
                m_strDBNotFoundErrorCode = (String)this.getProperties().get(SQLParams.DB_NOT_FOUND_ERROR_CODE);
                m_strDuplicateKeyErrorText = (String)this.getProperties().get(SQLParams.DUPLICATE_KEY_ERROR_TEXT);
                if (m_strDuplicateKeyErrorText != null)
                    m_strDuplicateKeyErrorText = m_strDuplicateKeyErrorText.toLowerCase();
                m_strDuplicateKeyErrorCode = (String)this.getProperties().get(SQLParams.DUPLICATE_KEY_ERROR_CODE);
                m_strKeyNotFoundErrorText = (String)this.getProperties().get(SQLParams.KEY_NOT_FOUND_ERROR_TEXT);
                if (m_strKeyNotFoundErrorText != null)
                    m_strKeyNotFoundErrorText = m_strDuplicateKeyErrorText.toLowerCase();
                m_strKeyNotFoundErrorCode = (String)this.getProperties().get(SQLParams.KEY_NOT_FOUND_ERROR_CODE);
                m_strRecordLockedErrorText = (String)this.getProperties().get(SQLParams.RECORD_LOCKED_ERROR_TEXT);
                if (m_strRecordLockedErrorText != null)
                    m_strRecordLockedErrorText = m_strRecordLockedErrorText.toLowerCase();
                m_strRecordLockedErrorCode = (String)this.getProperties().get(SQLParams.RECORD_LOCKED_ERROR_CODE);
                m_strBrokenPipeErrorText = (String)this.getProperties().get(SQLParams.BROKEN_PIPE_ERROR_TEXT);
                if (m_strBrokenPipeErrorText != null)
                    m_strBrokenPipeErrorText = m_strBrokenPipeErrorText.toLowerCase();
                m_strBrokenPipeErrorCode = (String)this.getProperties().get(SQLParams.BROKEN_PIPE_ERROR_CODE);
            }
                // Yeah, I know this is slow, but exceptions are not that common.
            if (this.checkForError(ex, DBConstants.FILE_NOT_FOUND, m_strFileNotFoundErrorText, m_strFileNotFoundErrorCode))
                iError = DBConstants.FILE_NOT_FOUND;
            if (this.checkForError(ex, DBConstants.DB_NOT_FOUND, m_strDBNotFoundErrorText, m_strDBNotFoundErrorCode))
                iError = DBConstants.DB_NOT_FOUND;
            if (this.checkForError(ex, DBConstants.DUPLICATE_KEY, m_strDuplicateKeyErrorText, m_strDuplicateKeyErrorCode))
                iError = DBConstants.DUPLICATE_KEY;
            if (this.checkForError(ex, DBConstants.DUPLICATE_COUNTER, m_strDuplicateKeyErrorText, m_strDuplicateKeyErrorCode))
                iError = DBConstants.DUPLICATE_COUNTER;
            if (this.checkForError(ex, DBConstants.KEY_NOT_FOUND, m_strKeyNotFoundErrorText, m_strKeyNotFoundErrorCode))
                iError = DBConstants.KEY_NOT_FOUND;
            if (this.checkForError(ex, DBConstants.RECORD_LOCKED, m_strRecordLockedErrorText, m_strRecordLockedErrorCode))
                iError = DBConstants.RECORD_LOCKED;
            if (this.checkForError(ex, DBConstants.BROKEN_PIPE, m_strBrokenPipeErrorText, m_strBrokenPipeErrorCode))
                iError = DBConstants.BROKEN_PIPE;
        }
        if (iError == DBConstants.ERROR_RETURN)
        {
            Utility.getLogger().info("Unknown sql exception: " + strMessage);
            eDB = new DatabaseException(strMessage);
        }
        else if (iError == DBConstants.RECORD_LOCKED)
            eDB = new DatabaseException(iError, strMessage);    // On locked, tells user/computer
        else
            eDB = new DatabaseException(iError);    // Standard error
        return eDB;
    }
507928
public static <T, E extends RuntimeException> ExceptionSupplier<T, E> throwA(E exception) {
        return new ExceptionSupplier<>(exception);
    }
1358206
private void reportException(Exception ex) {

		final Map<String, Object> data = new LinkedHashMap<>();

		data.put("type",       getJobExceptionMessageType());
		data.put("jobtype",    getJobType());
		data.put("username",   getUsername());

		TransactionCommand.simpleBroadcastException(ex, data, true);
	}
120084
@Nonnull
    LessException createException( Throwable cause ) {
        LessException lessEx = cause.getClass() == LessException.class ? (LessException)cause : new LessException( cause );
        lessEx.addPosition( filename, line, column );
        return lessEx;
    }
1039845
public static void asUnchecked(Throwable t, Class<? extends RuntimeException> checkedExceptionWrapper) {
        if (t instanceof AssertionError) {
            throw (AssertionError) t;
        } else if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else {
            RuntimeException exception;
            try {
                exception = checkedExceptionWrapper.getConstructor(Throwable.class).newInstance(t);
            } catch (Exception e) {
                throw new RuntimeException(t);
            }
            throw exception;
        }
    }
967575
public static RuntimeException getRuntimeException(final Throwable exc) {
        Throwable e = exc;
        while (e.getCause() instanceof RuntimeException) {
            e = e.getCause();
        }
        if (e instanceof RuntimeException) {
            return (RuntimeException) e;
        } else {
            return new RuntimeException(exc);
        }
    }
1093362
protected NaaccrIOException convertSyntaxException(ConversionException ex) {
        String msg = ex.get("message");
        if (msg == null)
            msg = ex.getMessage();
        NaaccrIOException e = new NaaccrIOException(msg, ex);
        if (ex.get("line number") != null)
            e.setLineNumber(Integer.valueOf(ex.get("line number")));
        e.setPath(ex.get("path"));
        return e;
    }
1005438
public static String formatException(final Exception e) {
    final StringBuilder sb = new StringBuilder();
    Throwable t = e;
    while (t != null) {
      sb.append(t.getMessage()).append("\n");
      t = t.getCause();
    }
    return sb.toString();
  }
410224
public static Throwable unwrapCause(Throwable e) {
        if (e instanceof CommandActionExecutionException) {
            return e.getCause();
        }
        if (e instanceof HystrixBadRequestException) {
            return e.getCause();
        }
        return e;
    }
119782
public static String exceptionList(Throwable ex) { 
        StringBuilder sb = new StringBuilder();

        sb.append("<=================================>");
        sb.append("Exception Message -> ");
        sb.append(ex.getMessage());
        sb.append(nl);
        if (ex instanceof ResourceException) {
            sb.append("  ResourceException Error Code -> ");
            sb.append(((ResourceException) ex).getErrorCode());
            sb.append(nl);
        }
        if (ex instanceof SQLException) {
            sb.append("  SQLException  Error Code -> ");
            sb.append(((SQLException) ex).getErrorCode());
            sb.append(nl);
            sb.append("  SQLException  SQLState -> ");
            sb.append(((SQLException) ex).getSQLState());
            sb.append(nl);
        }
        // Get stack trace of current exception
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        ex.printStackTrace(pw);
        sb.append(sw.getBuffer());
        sb.append("<=================================>");

        // If exception supports linked exceptions, get linked exception
        Throwable ex2 = null;
        ex2 = ex.getCause();

        // If we got a linked exception, recursively call this method
        if (ex2 != null) {
            sb.append("Next Linked Exception:" + nl);
            sb.append(exceptionList(ex2));
        }

        return sb.toString();

    }
1293289
final int recordExceptionalCompletion(Throwable ex) {
        int s;
        if ((s = status) >= 0) {
            int h = System.identityHashCode(this);
            final ReentrantLock lock = exceptionTableLock;
            lock.lock();
            try {
                expungeStaleExceptions();
                ExceptionNode[] t = exceptionTable;
                int i = h & (t.length - 1);
                for (ExceptionNode e = t[i]; ; e = e.next) {
                    if (e == null) {
                        t[i] = new ExceptionNode(this, ex, t[i]);
                        break;
                    }
                    if (e.get() == this) // already present
                        break;
                }
            } finally {
                lock.unlock();
            }
            s = setCompletion(EXCEPTIONAL);
        }
        return s;
    }
38334
public static String exception2String(Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        return sw.toString().trim();
    }
1305983
public function formatException(\Exception $ex)
    {
        return sprintf(
            $this->errorMessageFormat,
            $ex->getMessage(),
            $ex->getCode(),
            $ex->getFile(),
            $ex->getLine(),
            get_class($ex)
        );
    }
20099
private int onException(Exception e) throws IOException {
        eofReached = true;
        if (e instanceof IOException) {
            throw (IOException) e;
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            // Impossible since InputStream throws no other checked exceptions.
            throw Throwables.failure(e);
        }
    }
624623
private EJBException mapException(Throwable ex)
    {
        EJBException ejbex;
        boolean createdEx = true;
        Exception causeEx = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "mapException: " + ex);

        // -----------------------------------------------------------------------
        // First, obtain the message text used to create the exception.
        //
        // If the message being mapped ends up being 'replaced', then the
        // replacement should have the same message text.
        //
        // getBaseMessage insures that the message text does NOT include the
        // name of the exception class, nor any chained exception text.
        // -----------------------------------------------------------------------
        String message = ExceptionUtil.getBaseMessage(ex);

        // -----------------------------------------------------------------------
        // Second, get the cause of the exception being mapped.
        //
        // findCause will remove any internal EJB Container exceptions from
        // the exception chain.
        //
        // Also, if the cause is not a subclass of Throwable, then it must
        // be 'wrapped' in an Exception, as EJBException does not allow
        // Throwable on any of its constructors.  However, the 'cause' on
        // throwable will still be set to the intended cause.  This will allow
        // getCause() to work as expected, even though EJBException does not
        // support Throwable.
        // -----------------------------------------------------------------------
        Throwable cause = ExceptionUtil.findCause(ex);

        if (cause != null)
        {
            if (cause instanceof Exception)
            {
                causeEx = (Exception) cause;
            }
            else
            {
                causeEx = new Exception("See nested Throwable", cause);
            }
        }

        // -----------------------------------------------------------------------
        // Next, map Throwable to an EJBException to return.
        //
        // These mappings are prescribed by the EJB & ActivitySession specs.
        //
        // Note: When adding new mappings, do NOT call 'initCause', as that
        //       will be performed below, and handles the fact that EJBException
        //       may not be created with a throwable.
        //
        // Caution: Do NOT look at the cause to perform mapping. If an exception
        //          is 'wrapped' in another exception, it likely was wrapped
        //          by another EJB method call, and a failure from a downstream
        //          method call should NOT be treated the same here.
        //          If it appears the cause needs to be examined, then instead,
        //          find the code that wrapped the cause, and stop wrapping it.
        // -----------------------------------------------------------------------
        if (ex instanceof CSIException)
        {
            ejbex = mapCSIException((CSIException) ex, causeEx, cause);
            createdEx = false;
        }
        else if (ex instanceof NoSuchObjectException)
        {
            ejbex = new NoSuchEJBException(message, causeEx);
        }
        else if (ex instanceof EJBStoppedException) // d350987
        {
            // Don't just replace the EJBStoppedException, but nest it as the
            // cause so applications may check for it.
            cause = ex;
            causeEx = (Exception) ex;
            ejbex = new NoSuchEJBException((String) null, causeEx);
        }
        else if (ex instanceof TransactionRequiredException)
        {
            ejbex = new EJBTransactionRequiredException(message); // d395666
        }
        else if (ex instanceof TransactionRolledbackException)
        {
            ejbex = new EJBTransactionRolledbackException(message, causeEx); // d395666
        }
        else if (ex instanceof InvalidTransactionException)
        {
            ejbex = new InvalidTransactionLocalException(message, causeEx);
        }
        else if (ex instanceof AccessException)
        {
            ejbex = new EJBAccessException(message); // d395666
        }
        //        else if (ex instanceof ActivityRequiredException)
//        {
//            ejbex = new ActivityRequiredLocalException(message, causeEx);
//        }
//        else if (ex instanceof InvalidActivityException)
//        {
//            ejbex = new InvalidActivityLocalException(message, causeEx);
//        }
//        else if (ex instanceof ActivityCompletedException)
//        {
//            ejbex = new ActivityCompletedLocalException(message, causeEx);
//        }
        else if (ex instanceof BeanNotReentrantException)
        {
            BeanNotReentrantException bnre = (BeanNotReentrantException) ex;
            if (bnre.isTimeout())
            {
                // EJB 3.1 has defined an exception for this purpose.      d653777.1
                ejbex = new ConcurrentAccessTimeoutException(message);
            }
            else
            {
                // EJB 3.0 has defined an exception for this purpose.      d366807.6
                ejbex = new ConcurrentAccessException(message, causeEx);
            }
        }
        else
        {
            // --------------------------------------------------------------------
            // All other exceptions are just be mapped to an EJBException.
            //
            // If the exception is an EJBException, it will just be returned
            // (with the throwable cause filled in), else the exception will
            // just be wrapped in an EJBException, with the stack and cause
            // set appropriately.
            // --------------------------------------------------------------------
            ejbex = ExceptionUtil.EJBException(ex);
            createdEx = false;
        }

        // -----------------------------------------------------------------------
        // Finally, EJBException doesn't normally set the cause on Throwable,
        // so let's do that to be nice :-) and clear the stack of the
        // EJBException, as it is mostly confusing and causes very
        // similar stacks to be printed out twice.
        //
        // Note that this code, especially clearing of the stack, is only
        // performed for EJBExceptions that were created in this method.
        // EJBExceptions that will just be propagated should NOT have the
        // stack cleared, as they were likely thrown by the customer.
        // -----------------------------------------------------------------------
        if (createdEx)
        {
            if (causeEx != null)
            {
                // Intentionally, the 'cause' is set as the 'cause', and not
                // 'causeEx'.  They will be the same, except when 'causeEx'
                // is just a silly wrapper around a Throwable.
                //
                // Geronimo EJBException.getCause returns getCausedbyException, so
                // we do not expect this code to be used.                     F53643
                if (ejbex.getCause() == null) { //F743-16279
                    // Use the 'real' cause here, not the possibly wrapped one.
                    ejbex.initCause(cause);
                }
            }
            else
            {
                ejbex.setStackTrace(ex.getStackTrace());
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "mapException returning: " + ejbex);

        return ejbex;
    }