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