View Javadoc
1   package org.opentrafficsim.core.geometry;
2   
3   
4   /**
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    * $LastChangedDate: 2015-07-16 10:20:53 +0200 (Thu, 16 Jul 2015) $, @version $Revision: 1124 $, by $Author: pknoppers $,
10   * initial version Jul 22, 2015 <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 OTSGeometryException extends Exception
15  {
16      /** */
17      private static final long serialVersionUID = 20150722L;
18  
19      /**
20       * construct empty OTSGeometryException.
21       */
22      public OTSGeometryException()
23      {
24          super();
25      }
26  
27      /**
28       * @param message message to display for this exception.
29       */
30      public OTSGeometryException(final String message)
31      {
32          super(message);
33      }
34  
35      /**
36       * @param cause the exception that triggered this exception.
37       */
38      public OTSGeometryException(final Throwable cause)
39      {
40          super(cause);
41      }
42  
43      /**
44       * @param message message to display for this exception.
45       * @param cause the exception that triggered this exception.
46       */
47      public OTSGeometryException(final String message, final Throwable cause)
48      {
49          super(message, cause);
50      }
51  
52      /**
53       * @param message message to display for this exception.
54       * @param cause the exception that triggered this exception.
55       * @param enableSuppression whether or not suppression is enabled or disabled
56       * @param writableStackTrace whether or not the stack trace should be writable
57       */
58      public OTSGeometryException(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 OTSGeometryException the exception to throw on true condition
69       */
70      public static void failIf(final boolean condition, final String message) throws OTSGeometryException
71      {
72          if (condition)
73          {
74              StackTraceElement[] ste = new Exception().getStackTrace();
75              String where = ste[1].getClassName() + "." + ste[1].getMethodName() + " (" + ste[1].getLineNumber() + "): ";
76              throw new OTSGeometryException(where + message);
77          }
78      }
79  
80  }