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