2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.config;
22 * Exception thrown to indicate that a
23 * configuration property has an invalid value. It is thrown by
24 * several methods in {@link Configuration} and can be thrown by any
25 * component that reads the configuration.
27 public class IllegalParameterException extends RuntimeException {
29 // ================== initialization =====================================
30 // =======================================================================
33 * Calls super constructor. It passes a string message which is the given
34 * message, prefixed with the given property name.
35 * @param name Name of configuration property that is invalid
36 * @param message Additional info about why the value is invalid
38 public IllegalParameterException(String name, String message) {
40 super("Parameter \"" + name + "\": " + message);
43 // ================== methods ============================================
44 // =======================================================================
47 * Extends message with info from stack trace.
48 * It tries to guess what class called {@link Configuration} and
49 * adds relevant info from the stack trace about it to the message.
51 public String getMessage() {
53 StackTraceElement[] stack = getStackTrace();
55 // Search the element that invoked Configuration
56 // It's the first whose class is different from Configuration
58 for (pos=0; pos < stack.length; pos++)
60 if (!stack[pos].getClassName().equals(
61 Configuration.class.getName()))
65 return super.getMessage()+"\nAt "+
66 getStackTrace()[pos].getClassName()+"."+
67 getStackTrace()[pos].getMethodName()+":"+
68 getStackTrace()[pos].getLineNumber();
72 * Returns the exception message without stack trace information
74 public String getShortMessage()
76 return super.getMessage();