View Javadoc

1   package org.lcsim.recon.tracking.trfutil;
2   /**
3    * Assert is modelled on the C++ assert macro.
4    * It throws an AssertException if the boolean result of an
5    * expression is false.
6    * By making AssertException a RuntimeException the client
7    * is not forced to use a try-catch block.
8    * Therefore we explicitly print the StackTrace when the exception
9    * is thrown.
10   *
11   * @author Norman A. Graf
12   * @version 1.0
13   */
14  public final class Assert
15  {
16      /**
17       * Assert is a wrapper class for its assert method.
18       *
19       */
20      private Assert()
21      {
22      }
23      
24      /**
25       * This method throws a runtime exception if its argument is false at runtime.
26       *
27       * @param   result expression which resolves to boolean
28       */
29      public static void assertTrue( boolean result )
30      {
31          if ( !result )
32          {
33              AssertException ex = new AssertException( "Assertion Failed!" );
34              ex.printStackTrace();
35              throw ex;
36          }
37      }
38  }