Search in sources :

Example 1 with CustomTypeException

use of lucee.runtime.exp.CustomTypeException in project Lucee by lucee.

the class Throw method _doStartTag.

private void _doStartTag(Object obj) throws PageException {
    if (!StringUtil.isEmpty(obj)) {
        PageException pe = toPageException(obj, null);
        if (pe != null)
            throw pe;
        CustomTypeException exception = new CustomTypeException(Caster.toString(obj), detail, errorcode, type, extendedinfo, level);
        throw exception;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) CustomTypeException(lucee.runtime.exp.CustomTypeException)

Example 2 with CustomTypeException

use of lucee.runtime.exp.CustomTypeException in project Lucee by lucee.

the class Throw method toPageException.

public static PageException toPageException(Object object, PageException defaultValue) throws PageException {
    if ((object instanceof ObjectWrap))
        return toPageException(((ObjectWrap) object).getEmbededObject(), defaultValue);
    if (object instanceof CatchBlock) {
        CatchBlock cb = (CatchBlock) object;
        return cb.getPageException();
    }
    if (object instanceof PageException)
        return (PageException) object;
    if (object instanceof Throwable) {
        Throwable t = (Throwable) object;
        return new CustomTypeException(t.getMessage(), "", "", t.getClass().getName(), "");
    }
    if (object instanceof Struct) {
        Struct sct = (Struct) object;
        String type = Caster.toString(sct.get(KeyConstants._type, ""), "").trim();
        String msg = Caster.toString(sct.get(KeyConstants._message, null), null);
        if (!StringUtil.isEmpty(msg, true)) {
            String detail = Caster.toString(sct.get(KeyConstants._detail, null), null);
            String errCode = Caster.toString(sct.get("ErrorCode", null), null);
            String extInfo = Caster.toString(sct.get("ExtendedInfo", null), null);
            PageException pe = null;
            if ("application".equalsIgnoreCase(type))
                pe = new ApplicationException(msg, detail);
            else if ("expression".equalsIgnoreCase(type))
                pe = new ExpressionException(msg, detail);
            else
                pe = new CustomTypeException(msg, detail, errCode, type, extInfo);
            // Extended Info
            if (!StringUtil.isEmpty(extInfo, true))
                pe.setExtendedInfo(extInfo);
            // Error Code
            if (!StringUtil.isEmpty(errCode, true))
                pe.setErrorCode(errCode);
            // Additional
            if (pe instanceof PageExceptionImpl) {
                PageExceptionImpl pei = (PageExceptionImpl) pe;
                sct = Caster.toStruct(sct.get("additional", null), null);
                if (sct != null) {
                    Iterator<Entry<Key, Object>> it = sct.entryIterator();
                    Entry<Key, Object> e;
                    while (it.hasNext()) {
                        e = it.next();
                        pei.setAdditional(e.getKey(), e.getValue());
                    }
                }
            }
            return pe;
        }
    }
    return defaultValue;
}
Also used : PageException(lucee.runtime.exp.PageException) ObjectWrap(lucee.runtime.type.ObjectWrap) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) ApplicationException(lucee.runtime.exp.ApplicationException) CatchBlock(lucee.runtime.exp.CatchBlock) CustomTypeException(lucee.runtime.exp.CustomTypeException) Key(lucee.runtime.type.Collection.Key)

Aggregations

CustomTypeException (lucee.runtime.exp.CustomTypeException)2 PageException (lucee.runtime.exp.PageException)2 Entry (java.util.Map.Entry)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 CatchBlock (lucee.runtime.exp.CatchBlock)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 PageExceptionImpl (lucee.runtime.exp.PageExceptionImpl)1 Key (lucee.runtime.type.Collection.Key)1 ObjectWrap (lucee.runtime.type.ObjectWrap)1 Struct (lucee.runtime.type.Struct)1