View Javadoc
1   package org.opentrafficsim.simulationengine.properties;
2   
3   
4   /**
5    * Exception thrown when an operation is attempted that is not compatible with the indicated property.
6    * <p>
7    * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
8    * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
9    * <p>
10   * $LastChangedDate: 2016-03-29 03:26:55 +0200 (Tue, 29 Mar 2016) $, @version $Revision: 1866 $, by $Author: averbraeck $,
11   * initial version 18 dec. 2014 <br>
12   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
13   */
14  public class PropertyException extends Exception
15  {
16      /**  */
17      private static final long serialVersionUID = 20141023L;
18  
19      /**
20       * Construct a new IncompatiblePropertyException.
21       */
22      public PropertyException()
23      {
24          super();
25      }
26  
27      /**
28       * Construct a new IncompatiblePropertyException.
29       * @param message String; description of the problem
30       */
31      public PropertyException(final String message)
32      {
33          super(message);
34      }
35  
36      /**
37       * Construct a new IncompatiblePropertyException.
38       * @param cause Throwable; the cause of this ValueException
39       */
40      public PropertyException(final Throwable cause)
41      {
42          super(cause);
43      }
44  
45      /**
46       * Construct a new IncompatiblePropertyException.
47       * @param message String; description of the problem
48       * @param cause Throwable; the cause of this ValueException
49       */
50      public PropertyException(final String message, final Throwable cause)
51      {
52          super(message, cause);
53      }
54  
55      /**
56       * Construct a new IncompatiblePropertyException.
57       * @param message String; description of the problem
58       * @param cause Throwable; the cause of this ValueException
59       * @param enableSuppression boolean; whether or not suppression is enabled or disabled
60       * @param writableStackTrace boolean; whether or not the stack trace should be writable
61       */
62      public PropertyException(final String message, final Throwable cause, final boolean enableSuppression,
63          final boolean writableStackTrace)
64      {
65          super(message, cause, enableSuppression, writableStackTrace);
66      }
67  
68      /**
69       * Throw an Exception if a condition is met, e.g. for pre- and postcondition checking.
70       * @param condition the condition to check; an exception will be thrown if this is <b>true</b>
71       * @param message the message to use in the exception
72       * @throws PropertyException the exception to throw on true condition
73       */
74      public static void failIf(final boolean condition, final String message) throws PropertyException
75      {
76          if (condition)
77          {
78              StackTraceElement[] ste = new Exception().getStackTrace();
79              String where = ste[1].getClassName() + "." + ste[1].getMethodName() + " (" + ste[1].getLineNumber() + "): ";
80              throw new PropertyException(where + message);
81          }
82      }
83  }