Get BadRequestException from the exception

@param ex the exception
@return BadRequestException
516291
private BadRequestException getBadRequestException(Exception ex) {
	    return (BadRequestException) ExceptionUtils
	            .getThrowables(ex)[ExceptionUtils.indexOfThrowable(ex, BadRequestException.class)];
	}
728097
public ValidationException getException() {
        StringBuilder exceptionMessage = new StringBuilder();
        for (Problem problem : problems) {
            exceptionMessage.append(String.format("\n%s: %s", problem.getContext().getPath(), problem.getMessage()));
        }
        return new ValidationException(exceptionMessage.toString());
    }
748276
public static EvernoteException convert(Exception ex) {
		// construct exception message
		final StringBuilder sb = new StringBuilder();
		sb.append(ex.getClass().getName());
		if (ex instanceof EDAMUserException) {
			final EDAMErrorCode errorCode = ((EDAMUserException) ex).getErrorCode();
			if (errorCode == null) {
				sb.append(", ErrorCode [null");
			} else {
				sb.append(", ErrorCode [" + errorCode + "(" + errorCode.getValue() + ")");
			}
			sb.append("], Parameter [");
			sb.append(((EDAMUserException) ex).getParameter());
			sb.append("]");
		} else if (ex instanceof EDAMSystemException) {
			final EDAMErrorCode errorCode = ((EDAMSystemException) ex).getErrorCode();
			if (errorCode == null) {
				sb.append(", ErrorCode [null");
			} else {
				sb.append(", ErrorCode [" + errorCode + "(" + errorCode.getValue() + ")");
			}
			sb.append("], Message [");
			sb.append(((EDAMSystemException) ex).getMessage());
			sb.append("], RateLimitDuration [");
			sb.append(((EDAMSystemException) ex).getRateLimitDuration());
			sb.append("]");
		} else if (ex instanceof EDAMNotFoundException) {
			sb.append(", Identifier [");
			sb.append(((EDAMNotFoundException) ex).getIdentifier());
			sb.append("], Key [");
			sb.append(((EDAMNotFoundException) ex).getKey());
			sb.append("]");
		} else {
			sb.append(", Message [");
			sb.append(ex.getMessage());
			sb.append("]");
		}
		return new EvernoteException(sb.toString(), ex);
	}
456239
private void responseErrorToClient(Exception ex, User user) {
	    BadRequestException e = getBadRequestException(ex);
	    if(!e.isSendToClient())    return;
	    ISFSObject params = new SFSObject();
	    params.putUtfString(APIKey.MESSAGE, e.getReason());
	    params.putInt(APIKey.CODE, e.getCode());
	    send(APIKey.ERROR, params, user);
	}
894764
@Override
	protected void handleException(final SqlContext sqlContext, final SQLException ex) throws SQLException {
		SQLException cause = ex;

		while (cause.getNextException() != null) {
			cause = cause.getNextException();
		}

		if (LOG.isErrorEnabled() && isOutputExceptionLog()) {
			StringBuilder builder = new StringBuilder();
			builder.append(System.lineSeparator()).append("Exception occurred in SQL execution.")
					.append(System.lineSeparator());
			builder.append("Executed SQL[").append(sqlContext.getExecutableSql()).append("]")
					.append(System.lineSeparator());
			if (sqlContext instanceof SqlContextImpl) {
				Parameter[] bindParameters = ((SqlContextImpl) sqlContext).getBindParameters();
				for (int i = 0; i < bindParameters.length; i++) {
					Parameter parameter = getSqlFilterManager().doParameter(bindParameters[i]);
					builder.append("Bind Parameter.[INDEX[").append(i + 1).append("], ").append(parameter.toString())
							.append("]").append(System.lineSeparator());
				}
			}
			LOG.error(builder.toString(), cause);
		}

		throw cause;
	}
1340182
private boolean isExceptionHandled(String ex) {
        try {
            JavaClass thrownEx = Repository.lookupClass(ex);
            // First look at the throws clause
            ExceptionTable et = getMethod().getExceptionTable();
            if (et != null) {
                String[] throwClauseExNames = et.getExceptionNames();
                for (String throwClauseExName : throwClauseExNames) {
                    JavaClass throwClauseEx = Repository.lookupClass(throwClauseExName);
                    if (thrownEx.instanceOf(throwClauseEx)) {
                        return true;
                    }
                }
            }
            // Next look at the try catch blocks
            CodeException[] catchExs = getCode().getExceptionTable();
            if (catchExs != null) {
                int pc = getPC();
                for (CodeException catchEx : catchExs) {
                    if ((pc >= catchEx.getStartPC()) && (pc <= catchEx.getEndPC())) {
                        int type = catchEx.getCatchType();
                        if (type != 0) {
                            String catchExName = getConstantPool().getConstantString(type, Const.CONSTANT_Class);
                            JavaClass catchException = Repository.lookupClass(catchExName);
                            if (thrownEx.instanceOf(catchException)) {
                                return true;
                            }
                        }
                    }
                }
            }
        } catch (ClassNotFoundException cnfe) {
            bugReporter.reportMissingClass(cnfe);
        }
        return false;
    }
958617
private int setExceptionalCompletion(Throwable ex) {
        int s = recordExceptionalCompletion(ex);
        if ((s & DONE_MASK) == EXCEPTIONAL)
            internalPropagateException(ex);
        return s;
    }
1140215
private static <E extends RuntimeException> E handleException(E ex) {
        if (JodaTime.hasExpectedBehavior())
            return ex;
        throw new IllegalStateException("Joda-time 2.2 or later version is required, but found version: " + JodaTime.getVersion(), ex);
    }
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);
        }
    }
221040
public static ErrorDescription create(ApplicationException ex) {
    	ErrorDescription description = new ErrorDescription();
    	description.setCategory(ex.getCategory());
    	description.setStatus(ex.getStatus());
    	description.setCode(ex.getCode());
    	description.setMessage(ex.getMessage());
    	description.setDetails(ex.getDetails());
    	description.setCorrelationId(ex.getCorrelationId());    	
    	description.setCause(ex.getCauseString());    	
    	description.setStackTrace(ex.getStackTraceString());    	
    	return description;
    }
1331633
public static void print_exception(Exception ex) {

        if (ex instanceof DevFailed) {
//
// For a Tango DevFailed exception
//

            DevFailed ex_dev = ((fr.esrf.Tango.DevFailed) ex);
            for (int i = 0; i < ex_dev.errors.length; i++) {
                System.err.println("Tango exception");
                System.err.print("Severity -> ");
                switch (ex_dev.errors[i].severity.value()) {
                    case ErrSeverity._WARN:
                        System.err.println("WARNING ");
                        break;

                    case ErrSeverity._ERR:
                        System.err.println("ERROR ");
                        break;

                    case ErrSeverity._PANIC:
                        System.err.println("PANIC ");
                        break;

                    default:
                        System.err.println("Unknown severity code");
                        break;
                }
                System.err.println("Desc -> " + ex_dev.errors[i].desc);

                //	Check if from a MultiDevFailed exception
                if (ex instanceof NamedDevFailedList) {
                    NamedDevFailedList ndfl = (NamedDevFailedList) ex;
                    if (i < ndfl.get_faulty_attr_nb()) {
                        NamedDevFailed ndf = ndfl.elementAt(i);
                        for (DevError err : ndf.err_stack)
                            System.out.println("Reason -> " + err.reason);
                    }
                } else
                    System.err.println("Reason -> " + ex_dev.errors[i].reason);
                System.err.println("Origin -> " + ex_dev.errors[i].origin);
            }
        } else {
            int last_dot, before_last_dot;
            String ex_name = ex.getClass().getName();
            if ((last_dot = ex_name.lastIndexOf('.')) < 0) {
                // Unknown exception
                System.err.println(ex.getMessage());
                ex.printStackTrace();
                return;
            }
            String ex_last_name = ex_name.substring(last_dot + 1);
            if ((before_last_dot = ex_name.lastIndexOf('.', last_dot - 1)) < 0) {
                // Unknown exception
                System.err.println(ex.getMessage());
                ex.printStackTrace();
                return;
            }

            String ex_part_name = ex_name.substring(before_last_dot + 1, last_dot);
            if (ex_part_name.equals("CORBA")) {
                // CORBA System exception
                SystemException ex_sys = ((SystemException) ex);
                System.err.println("CORBA system exception " + ex_last_name);
                System.err.println(ex.getMessage());
                System.err.print("Completed: ");
                switch (ex_sys.completed.value()) {
                    case CompletionStatus._COMPLETED_YES:
                        System.err.println("yes");
                        break;

                    case CompletionStatus._COMPLETED_NO:
                        System.err.println("no");
                        break;

                    case CompletionStatus._COMPLETED_MAYBE:
                        System.err.println("maybe");
                        break;
                }
                System.err.println("Minor code: " + ex_sys.minor);
            } else {
                // Unknown exeption
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }

        }
    }

    /**
     * Print a TANGO exception with stack.
     * <p/>
     * Print all the details of a TANGO exception. It also prints the stack when
     * the exception occurs. If the exception is not a TANGO DevFailed exception, it
     * only print the stack.
     *
     * @param ex The exception object reference
     */

    public static void print_exception_stack(Exception ex) {
        print_exception(ex);
        ex.printStackTrace();
    }

    //===============================================================
    /**
     * Returns the current code line (used as origin to throw a DevFailed)
     *
     * @return the current code line (used as origin to throw a DevFailed)
     */
    //===============================================================
    private static String getCurrentCodeLine() {
        //  index 0:    Thread.getTrace()
        //  index 1:    The following line.
        //  index 2:    The throw_exception() line.
        //  index 3:    the calling line.
        return Thread.currentThread().getStackTrace()[3].toString();
    }

    /**
     * Generate and throw a TANGO DevFailed exception.
     * <p/>
     * The exception is created with a single DevError
     * object. The DevError severity field is set to ERR
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field.
     *               origin will be find from java classes.
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void throw_exception(String reason, String desc) throws DevFailed {
        throw_exception(reason, desc, getCurrentCodeLine());
    }

    /**
     * Generate and throw a TANGO DevFailed exception.
     * <p/>
     * The exception is created with a single DevError
     * object. The DevError severity field is set to ERR
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void throw_exception(String reason, String desc, String origin)
            throws DevFailed {
        throw_exception(reason, desc, origin, ErrSeverity.ERR);
    }

    /**
     * Generate and throw a TANGO DevFailed exception.
     * <p/>
     * The exception is created with a single DevError
     * object.
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @param sever  The exception DevError object severity field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void throw_exception(String reason, String desc,
                                       String origin, ErrSeverity sever)
            throws DevFailed {
        DevError[] err = new DevError[1];
        err[0] = new DevError();

        err[0].desc = desc;
        err[0].severity = sever;
        err[0].reason = reason;
        err[0].origin = origin;

        throw new DevFailed(err);
    }

    /**
     * Re-throw a TANGO DevFailed exception with one more error.
     * <p/>
     * The exception is re-thrown with one more DevError
     * object. The new DevError severity field is set to ERR
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param ex     The DevFailed exception
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void re_throw_exception(DevFailed ex, String reason, String desc)
            throws DevFailed {
        re_throw_exception(ex, reason, desc, getCurrentCodeLine());
    }

    /**
     * Re-throw a TANGO DevFailed exception with one more error.
     * <p/>
     * The exception is re-thrown with one more DevError
     * object. The new DevError severity field is set to ERR
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param ex     The DevFailed exception
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void re_throw_exception(DevFailed ex,
                                          String reason, String desc, String origin)
            throws DevFailed {
        re_throw_exception(ex, reason, desc, origin, ErrSeverity.ERR);
    }

    /**
     * Re-throw a TANGO DevFailed exception with one more error.
     * <p/>
     * The exception is re-rhrown with one more DevError
     * object.
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param ex     The DevFailed exception
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @param sever  The exception DevError object severity field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void re_throw_exception(DevFailed ex,
                                          String reason, String desc, String origin, ErrSeverity sever)
            throws DevFailed {
        int nb_error = ex.errors.length;
        DevError[] err = new DevError[nb_error + 1];
        System.arraycopy(ex.errors, 0, err, 0, nb_error);
        err[nb_error] = new DevError();

        err[nb_error].desc = desc;
        err[nb_error].severity = sever;
        err[nb_error].reason = reason;
        err[nb_error].origin = origin;

        throw new DevFailed(err);
    }

    /**
     * Generate and throw a TANGO DevFailed exception from a CORBA exception.
     * <p/>
     * The exception is created with a single DevError
     * object. A value ERR is defined for the DevError
     * severity field.
     * Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     * <b>DevFailed</b> exception specification
     *
     * @param ex     A CORBA System Exception. The reason and desc fields of the
     *               DevError object will be set according to the data in this exception.
     *               The reason field is always set to API_CorbaSysException and the reason flag is
     *               different depending on the exact type of the CORBA system exception.
     * @param origin The exception DevError object origin field
     * @throws DevFailed The thrown exception.
     *                   Click <a href="../../tango_basic/idl_html/Tango.html#DevFailed">here</a> to read
     *                   <b>DevFailed</b> exception specification
     */
    public static void throw_exception(SystemException ex, String origin)
            throws DevFailed {
        DevError[] err = new DevError[1];
        err[0] = new DevError();

        err[0].desc = print_CORBA_SystemException(ex);
        err[0].severity = ErrSeverity.ERR;
        err[0].reason = "API_CorbaSysException";
        err[0].origin = origin;

        throw new DevFailed(err);
    }


    /**
     * Create a string from a CORBA excepition
     *
     * @param ex The CORBA exception
     */
    public static String print_CORBA_SystemException(SystemException ex) {

//
// get exception name
//

        String ex_name = ex.getClass().getName();
        int last_dot = ex_name.lastIndexOf('.');

//
// Unknown exception
//

        if (last_dot == -1) {
            return "Unknown system exception !!!!!!!!";
        }
        String ex_last_name = ex_name.substring(last_dot + 1);
        int before_last_dot = ex_name.lastIndexOf('.', last_dot - 1);

//
// Unknown exception
//

        if (before_last_dot == -1) {
            return "Unknown system exception !!!!!!!!";
        } else {
            String ex_part_name = ex_name.substring(before_last_dot + 1, last_dot);

            if (ex_part_name.equals("CORBA")) {

//
// CORBA System exception
//

                StringBuilder str = new StringBuilder("CORBA system exception ");
                str.append(ex_last_name);
                str.append(ex.getMessage());
                str.append("Completed: ");
                switch (ex.completed.value()) {
                    case CompletionStatus._COMPLETED_YES:
                        str.append("yes");
                        break;

                    case CompletionStatus._COMPLETED_NO:
                        str.append("no");
                        break;

                    case CompletionStatus._COMPLETED_MAYBE:
                        str.append("maybe");
                        break;
                }
                str.append("Minor code: ");
                str.append(ex.minor);

                return str.toString();
            } else {

//
// Unknown exeption
//
                return "Unknown system exception !!!!!!!!";

            }
        }
    }


//=======================================================================
/*
 *	Client exceptions management
 */
//=======================================================================
    //===================================================================
    /**
     * Throw a ConnectionFailed exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws ConnectionFailed The client exception.
     */
    //===================================================================
    static public void throw_connection_failed(String reason, String desc, String origin)
            throws ConnectionFailed {
        throw_connection_failed(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._PANIC));
    }
    //===================================================================
    /**
     * Re-throw a ConnectionFailed exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws ConnectionFailed The client exception.
     */
    //===================================================================
    static public void throw_connection_failed(DevFailed df, String reason, String desc, String origin)
            throws ConnectionFailed {
        throw_connection_failed(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._PANIC));
    }
    //===================================================================
    /**
     * Throw a ConnectionFailed exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws ConnectionFailed The client exception.
     */
    //===================================================================
    static public void throw_connection_failed(String reason, String desc, String origin, ErrSeverity severity)
            throws ConnectionFailed {
        throw_connection_failed(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a ConnectionFailed exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws ConnectionFailed The client exception.
     */
    //===================================================================
    static public void throw_connection_failed(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws ConnectionFailed {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new ConnectionFailed(err);
    }
    //===================================================================
    /**
     * Throw a CommunicationFailed exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws CommunicationFailed The client exception.
     */
    //===================================================================
    static public void throw_communication_failed(String reason, String desc, String origin)
            throws CommunicationFailed {
        throw_communication_failed(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a CommunicationFailed exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws CommunicationFailed The client exception.
     */
    //===================================================================
    static public void throw_communication_failed(DevFailed df, String reason, String desc, String origin)
            throws CommunicationFailed {
        throw_communication_failed(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a CommunicationTimeout exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws CommunicationTimeout The client exception.
     */
    //===================================================================
    static public void throw_communication_timeout(String reason, String desc, String origin)
            throws fr.esrf.TangoApi.CommunicationTimeout {
        throw_communication_timeout(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a CommunicationFailed exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws CommunicationFailed The client exception.
     */
    //===================================================================
    static public void throw_communication_failed(String reason, String desc, String origin, ErrSeverity severity)
            throws CommunicationFailed {
        throw_communication_failed(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a CommunicationFailed exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws CommunicationFailed The client exception.
     */
    //===================================================================
    static public void throw_communication_failed(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws CommunicationFailed {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new CommunicationFailed(err);
    }

    //===================================================================
    /**
     * re-throw a DevFailed in a CommunicationTimeout exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws CommunicationTimeout The client exception.
     */
    //===================================================================
    static public void throw_communication_timeout(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws fr.esrf.TangoApi.CommunicationTimeout {

        DevError[] err;
        int i = 0;

        //  if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //  Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new fr.esrf.TangoApi.CommunicationTimeout(err);
    }
    //===================================================================
    /**
     * Throw a WrongNameSyntax exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws WrongNameSyntax The client exception.
     */
    //===================================================================
    static public void throw_wrong_syntax_exception(String reason, String desc, String origin)
            throws WrongNameSyntax {
        throw_wrong_syntax_exception(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a WrongNameSyntax exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws WrongNameSyntax The client exception.
     */
    //===================================================================
    static public void throw_wrong_syntax_exception(DevFailed df, String reason, String desc, String origin)
            throws WrongNameSyntax {
        throw_wrong_syntax_exception(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a WrongNameSyntax exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws WrongNameSyntax The client exception.
     */
    //===================================================================
    static public void throw_wrong_syntax_exception(String reason, String desc, String origin, ErrSeverity severity)
            throws WrongNameSyntax {
        throw_wrong_syntax_exception(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a WrongNameSyntax exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws WrongNameSyntax The client exception.
     */
    //===================================================================
    static public void throw_wrong_syntax_exception(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws WrongNameSyntax {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new WrongNameSyntax(err);
    }

    //===================================================================
    /**
     * Throw a WrongData exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws WrongData The client exception.
     */
    //===================================================================
    static public void throw_wrong_data_exception(String reason, String desc, String origin)
            throws WrongData {
        throw_wrong_data_exception(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a WrongData exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws WrongData The client exception.
     */
    //===================================================================
    static public void throw_wrong_data_exception(DevFailed df, String reason, String desc, String origin)
            throws WrongData {
        throw_wrong_data_exception(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a WrongData exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws WrongData The client exception.
     */
    //===================================================================
    static public void throw_wrong_data_exception(String reason, String desc, String origin, ErrSeverity severity)
            throws WrongData {
        throw_wrong_data_exception(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a WrongData exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws WrongData The client exception.
     */
    //===================================================================
    static public void throw_wrong_data_exception(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws WrongData {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new WrongData(err);
    }

    //===================================================================
    /**
     * Throw a NonDbDevice exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws NonDbDevice The client exception.
     */
    //===================================================================
    static public void throw_non_db_exception(String reason, String desc, String origin)
            throws NonDbDevice {
        throw_non_db_exception(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a NonDbDevice exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws NonDbDevice The client exception.
     */
    //===================================================================
    static public void throw_non_db_exception(DevFailed df, String reason, String desc, String origin)
            throws NonDbDevice {
        throw_non_db_exception(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a NonDbDevice exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws NonDbDevice The client exception.
     */
    //===================================================================
    static public void throw_non_db_exception(String reason, String desc, String origin, ErrSeverity severity)
            throws NonDbDevice {
        throw_non_db_exception(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a NonDbDevice exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws NonDbDevice The client exception.
     */
    //===================================================================
    static public void throw_non_db_exception(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws NonDbDevice {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new NonDbDevice(err);
    }

    //===================================================================
    /**
     * Throw a NonSupportedFeature exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws NonSupportedFeature The client exception.
     */
    //===================================================================
    static public void throw_non_supported_exception(String reason, String desc, String origin)
            throws NonSupportedFeature {
        throw_non_supported_exception(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a NonSupportedFeature exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws NonSupportedFeature The client exception.
     */
    //===================================================================
    static public void throw_non_supported_exception(DevFailed df, String reason, String desc, String origin)
            throws NonSupportedFeature {
        throw_non_supported_exception(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
   /**
     * Throw a NonSupportedFeature exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws NonSupportedFeature The client exception.
     */
    //===================================================================
    static public void throw_non_supported_exception(String reason, String desc, String origin, ErrSeverity severity)
            throws NonSupportedFeature {
        throw_non_supported_exception(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a NonSupportedFeature exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws NonSupportedFeature The client exception.
     */
    //===================================================================
    static public void throw_non_supported_exception(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws NonSupportedFeature {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new NonSupportedFeature(err);
    }

    //===================================================================
    /**
     * Throw a AsynReplyNotArrived exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws AsynReplyNotArrived The client exception.
     */
    //===================================================================
    static public void throw_asyn_reply_not_arrived(String reason, String desc, String origin)
            throws AsynReplyNotArrived {
        throw_asyn_reply_not_arrived(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a AsynReplyNotArrived exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws AsynReplyNotArrived The client exception.
     */
    //===================================================================
    static public void throw_asyn_reply_not_arrived(DevFailed df, String reason, String desc, String origin)
            throws AsynReplyNotArrived {
        throw_asyn_reply_not_arrived(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a AsynReplyNotArrived exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws AsynReplyNotArrived The client exception.
     */
    //===================================================================
    static public void throw_asyn_reply_not_arrived(String reason, String desc, String origin, ErrSeverity severity)
            throws AsynReplyNotArrived {
        throw_asyn_reply_not_arrived(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a AsynReplyNotArrived exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws AsynReplyNotArrived The client exception.
     */
    //===================================================================
    static public void throw_asyn_reply_not_arrived(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws AsynReplyNotArrived {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new AsynReplyNotArrived(err);
    }

    //===================================================================
    /**
     * Throw a EventSystemFailed exception.
     *
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws EventSystemFailed The client exception.
     */
    //===================================================================
    static public void throw_event_system_failed(String reason, String desc, String origin)
            throws EventSystemFailed {
        throw_event_system_failed(null,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Re-throw a EventSystemFailed exception.
     *
     * @param df     A DevFailed exception to be rethrown.
     * @param reason The exception DevError object reason field
     * @param desc   The exception DevError object desc field
     * @param origin The exception DevError object origin field
     * @throws EventSystemFailed The client exception.
     */
    //===================================================================
    static public void throw_event_system_failed(DevFailed df, String reason, String desc, String origin)
            throws EventSystemFailed {
        throw_event_system_failed(df,
                reason, desc, origin, ErrSeverity.from_int(ErrSeverity._ERR));
    }
    //===================================================================
    /**
     * Throw a EventSystemFailed exception.
     *
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws EventSystemFailed The client exception.
     */
    //===================================================================
    static public void throw_event_system_failed(String reason, String desc, String origin, ErrSeverity severity)
            throws EventSystemFailed {
        throw_event_system_failed(null,
                reason, desc, origin, severity);
    }
    //===================================================================
    /**
     * re-throw a DevFailed in a EventSystemFailed exception.
     *
     * @param df       A DevFailed exception to be rethrown.
     * @param reason   The exception DevError object reason field
     * @param desc     The exception DevError object desc field
     * @param origin   The exception DevError object origin field
     * @param severity The exception DevError object severity field
     * @throws EventSystemFailed The client exception.
     */
    //===================================================================
    static public void throw_event_system_failed(DevFailed df, String reason, String desc, String origin, ErrSeverity severity)
            throws EventSystemFailed {

        DevError[] err;
        int i = 0;

        //	if DevFailed is null -> allocate
        if (df == null)
            err = new DevError[1];
        else {
            //	Else copy in new object
            err = new DevError[df.errors.length + 1];
            for (; i < df.errors.length; i++)
                err[i] = df.errors[i];
        }
        err[i] = new DevError(reason, severity, desc, origin);
        throw new EventSystemFailed(err);
    }

}
768036
@ExceptionHandler(UnrecognizedPropertyException.class)
    public ResponseEntity<?> handleUnrecognizedProperty(UnrecognizedPropertyException ex, HttpServletRequest request) {
        ErrorResponse response = new ErrorResponse();
        response.addFieldError(ex.getPropertyName(), ex.getMessage());
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
    }
1029169
public RuntimeException endQuietly(Throwable ex) {
    try {
      GLOBALS.clear();
      Futures fs = new Futures();
      for (Frame fr : FRAMES.values()) {
        for (Key<Vec> vec : fr.keys()) {
          Integer I = REFCNTS.get(vec);
          int i = (I == null ? 0 : I) - 1;
          if (i > 0) REFCNTS.put(vec, i);
          else {
            REFCNTS.remove(vec);
            vec.remove(fs);
          }
        }
        DKV.remove(fr._key, fs);   // Shallow remove, internal Vecs removed 1-by-1
      }
      fs.blockForPending();
      FRAMES.clear();
      REFCNTS.clear();
    } catch (Exception ex2) {
      Log.warn("Exception " + ex2 + " suppressed while cleaning up Rapids Session after already throwing " + ex);
    }
    return ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex);
  }
232124
private String getErrorCode(SQLException ex) {
        String result = null;
        SQLException nestedEx = null;

        if (ex.getErrorCode() != 0) {
            result = Integer.toString(ex.getErrorCode());
        }

        if (result == null) {
            nestedEx = ex.getNextException();
            if (nestedEx != null) {
                result = Integer.toString(nestedEx.getErrorCode());
            }
        }

        return result;
    }
210001
def errno_from_exception(self, ex):
        
        if hasattr(ex, 'errno'):
            return ex.errno
        elif ex.args:
            return ex.args[0]
        else:
            return None
393446
public ResponseEntity<T> handleException(E ex, HttpServletRequest req) {

        logException(ex, req);

        T body = createBody(ex, req);
        HttpHeaders headers = createHeaders(ex, req);

        return new ResponseEntity<>(body, headers, getStatus());
    }
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;
    }