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 **/ 019package lucee.runtime.exp; 020 021import lucee.commons.lang.StringUtil; 022import lucee.runtime.PageSource; 023import lucee.runtime.op.Caster; 024import lucee.transformer.util.CFMLString; 025 026 027/** 028 * Template Exception Object 029 */ 030public class TemplateException extends PageExceptionImpl { 031 032 /** 033 * @return the line 034 */ 035 public int getLine() { 036 return line; 037 } 038 039 /** 040 * @return the pageSource 041 */ 042 public PageSource getPageSource() { 043 return pageSource; 044 } 045 046 private int line; 047 private PageSource pageSource; 048 049 /** 050 * constructor of the template exception 051 * @param message Exception Message 052 */ 053 public TemplateException(String message) { 054 super(message,"template"); 055 } 056 057 /** 058 * constructor of the template exception 059 * @param message Exception Message 060 * @param detail Detailed Exception Message 061 */ 062 public TemplateException(String message, String detail) { 063 super(message,"template"); 064 setDetail(detail); 065 } 066 067 /** 068 * Constructor of the class 069 * @param cfml 070 * @param message 071 */ 072 public TemplateException(PageSource ps, int line, int column,String message) { 073 super(message,"template"); 074 //print.err(line+"+"+column); 075 addContext(ps,line,column,null); 076 this.line=line; 077 this.pageSource=ps; 078 } 079 080 /** 081 * Constructor of the class 082 * @param cfml 083 * @param message 084 */ 085 public TemplateException(CFMLString cfml, String message) { 086 this(cfml.getPageSource(),cfml.getLine(),cfml.getColumn(),message); 087 } 088 089 /** 090 * Constructor of the class 091 * @param cfml 092 * @param message 093 * @param detail 094 */ 095 public TemplateException(CFMLString cfml, String message, String detail) { 096 this(cfml.getPageSource(),cfml.getLine(),cfml.getColumn(),message); 097 setDetail(detail); 098 } 099 100 /** 101 * Constructor of the class 102 * @param cfml 103 * @param e 104 */ 105 public TemplateException(CFMLString cfml, Throwable e) { 106 this( 107 cfml, 108 StringUtil.isEmpty(e.getMessage())? 109 (Caster.toClassName(e)): 110 e.getMessage()); 111 setStackTrace(e.getStackTrace()); 112 } 113}