001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019
020package lucee.runtime.exp;
021
022import lucee.runtime.config.Config;
023import lucee.runtime.type.Collection;
024import lucee.runtime.type.KeyImpl;
025
026/**
027 *
028 *
029 * To change the template for this generated type comment go to
030 * Window>Preferences>Java>Code Generation>Code and Comments
031 */
032public class ExpressionException extends PageExceptionImpl {
033
034        private static final Collection.Key ERR_NUMBER = KeyImpl.intern("ErrNumber");
035        /**
036         * Class Constuctor
037         * @param message error message
038         */
039        public ExpressionException(String message) {
040                super(message,"expression"); 
041        }
042
043        /**
044         * Class Constuctor
045         * @param message error message
046         * @param detail detailed error message
047         */
048        public ExpressionException(String message, String detail) {
049                super(message,"expression");
050                setDetail(detail);
051        }
052        
053        @Override
054        public CatchBlock getCatchBlock(Config config) {
055                CatchBlock sct=super.getCatchBlock(config);
056                sct.setEL(ERR_NUMBER,new Double(0));
057                return sct;
058        }
059    /**
060     * @param e
061     * @return pageException
062     */
063    public static ExpressionException newInstance(Exception e) {
064        if(e instanceof ExpressionException) return (ExpressionException) e;
065        else if(e instanceof PageException) {
066            PageException pe=(PageException)e;
067                ExpressionException ee = new ExpressionException(pe.getMessage());
068                ee.detail=pe.getDetail();
069                ee.setStackTrace(pe.getStackTrace());
070                return ee;
071        }
072        else  {
073                ExpressionException ee = new ExpressionException(e.getMessage());
074                ee.setStackTrace(e.getStackTrace());
075                return ee;
076        }
077    }
078}