Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / config / MissingParameterException.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
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.
7  *
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.
12  *
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.
16  *
17  */
18
19 package peersim.config;
20
21 /**
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. 
26  */
27 public class MissingParameterException extends RuntimeException {
28
29 // ================== initialization =====================================
30 // =======================================================================
31
32 MissingParameterException(String name) {
33
34         super("Parameter \"" + name + "\" not found.");
35 }
36
37 MissingParameterException(String name, String motivation) {
38
39         super("Parameter \"" + name + "\" not found " + motivation);
40 }
41
42 // ================== methods ============================================
43 // =======================================================================
44
45 /**
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.
49 */
50 public String getMessage() {
51         
52         StackTraceElement[] stack = getStackTrace();
53
54         // Search the element that invoked Configuration
55         // It's the first whose class is different from Configuration
56         int pos;
57         for (pos=0; pos < stack.length; pos++) {
58                 if (!stack[pos].getClassName().equals(
59                         Configuration.class.getName()))
60                         break;
61         }
62
63         return super.getMessage()+"\nAt "+
64                 getStackTrace()[pos].getClassName()+"."+
65                 getStackTrace()[pos].getMethodName()+":"+
66                 getStackTrace()[pos].getLineNumber();
67 }
68
69 /**
70  * Returns the exception message without stack trace information
71  */
72 public String getShortMessage()
73 {
74         return super.getMessage();
75 }
76
77 }