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 is not defined. It is thrown exclusively by
24 * {@link Configuration}, since it is the only class that has access to the
25 * set of defined properties.
27 public class MissingParameterException extends RuntimeException {
29 // ================== initialization =====================================
30 // =======================================================================
32 MissingParameterException(String name) {
34 super("Parameter \"" + name + "\" not found.");
37 MissingParameterException(String name, String motivation) {
39 super("Parameter \"" + name + "\" not found " + motivation);
42 // ================== methods ============================================
43 // =======================================================================
46 * Extends message with info from stack trace.
47 * It tries to guess what class called {@link Configuration} and
48 * adds relevant info from the stack trace about it to the message.
50 public String getMessage() {
52 StackTraceElement[] stack = getStackTrace();
54 // Search the element that invoked Configuration
55 // It's the first whose class is different from Configuration
57 for (pos=0; pos < stack.length; pos++) {
58 if (!stack[pos].getClassName().equals(
59 Configuration.class.getName()))
63 return super.getMessage()+"\nAt "+
64 getStackTrace()[pos].getClassName()+"."+
65 getStackTrace()[pos].getMethodName()+":"+
66 getStackTrace()[pos].getLineNumber();
70 * Returns the exception message without stack trace information
72 public String getShortMessage()
74 return super.getMessage();