001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.scripting; 018 019import org.springframework.core.NestedRuntimeException; 020 021/** 022 * Exception to be thrown on script compilation failure. 023 * 024 * @author Juergen Hoeller 025 * @since 2.0 026 */ 027@SuppressWarnings("serial") 028public class ScriptCompilationException extends NestedRuntimeException { 029 030 private ScriptSource scriptSource; 031 032 033 /** 034 * Constructor for ScriptCompilationException. 035 * @param msg the detail message 036 */ 037 public ScriptCompilationException(String msg) { 038 super(msg); 039 } 040 041 /** 042 * Constructor for ScriptCompilationException. 043 * @param msg the detail message 044 * @param cause the root cause (usually from using an underlying script compiler API) 045 */ 046 public ScriptCompilationException(String msg, Throwable cause) { 047 super(msg, cause); 048 } 049 050 /** 051 * Constructor for ScriptCompilationException. 052 * @param scriptSource the source for the offending script 053 * @param msg the detail message 054 * @since 4.2 055 */ 056 public ScriptCompilationException(ScriptSource scriptSource, String msg) { 057 super("Could not compile " + scriptSource + ": " + msg); 058 this.scriptSource = scriptSource; 059 } 060 061 /** 062 * Constructor for ScriptCompilationException. 063 * @param scriptSource the source for the offending script 064 * @param cause the root cause (usually from using an underlying script compiler API) 065 */ 066 public ScriptCompilationException(ScriptSource scriptSource, Throwable cause) { 067 super("Could not compile " + scriptSource, cause); 068 this.scriptSource = scriptSource; 069 } 070 071 /** 072 * Constructor for ScriptCompilationException. 073 * @param scriptSource the source for the offending script 074 * @param msg the detail message 075 * @param cause the root cause (usually from using an underlying script compiler API) 076 */ 077 public ScriptCompilationException(ScriptSource scriptSource, String msg, Throwable cause) { 078 super("Could not compile " + scriptSource + ": " + msg, cause); 079 this.scriptSource = scriptSource; 080 } 081 082 083 /** 084 * Return the source for the offending script. 085 * @return the source, or {@code null} if not available 086 */ 087 public ScriptSource getScriptSource() { 088 return this.scriptSource; 089 } 090 091}