The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ PreConditionException

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using System;
  19.     using System.Diagnostics;
  20.    
  21.     static internal class Debug
  22.     {
  23.        
  24.         [Conditional("ASSERTION")]
  25.         public static void Assert(bool condition)
  26.         {
  27.             if (!condition)
  28.                 throw new AssertException("Assertion fired");
  29.         }
  30.        
  31.         [Conditional("ASSERTION")]
  32.         public static void Assert(bool condition, string message)
  33.         {
  34.             if (!condition)
  35.                 throw new AssertException(message);
  36.         }
  37.        
  38.         [Conditional("ASSERTION")]
  39.         public static void NotImplemented(string message)
  40.         {
  41.             throw new AssertException("Method Not Yet Implemented");
  42.         }
  43.        
  44.         [Conditional("ASSERTION")]
  45.         public static void PostCondition(bool condition)
  46.         {
  47.             if (!condition)
  48.                 throw new PostConditionException("PostCondition missed");
  49.         }
  50.        
  51.         [Conditional("ASSERTION")]
  52.         public static void PostCondition(bool condition, string message)
  53.         {
  54.             if (!condition)
  55.                 throw new PostConditionException(message);
  56.         }
  57.        
  58.         [Conditional("ASSERTION")]
  59.         public static void PreCondition(bool condition)
  60.         {
  61.             if (!condition)
  62.                 throw new PreConditionException("PreCondition missed");
  63.         }
  64.        
  65.         [Conditional("ASSERTION")]
  66.         public static void PreCondition(bool condition, string message)
  67.         {
  68.             if (!condition)
  69.                 throw new PreConditionException(message);
  70.         }
  71.        
  72.         [Conditional("LOGGING")]
  73.         public static void Print(string str)
  74.         {
  75.             ScriptStream.Out.WriteLine(str);
  76.         }
  77.        
  78.         [Conditional("LOGGING")]
  79.         static internal void PrintLine(string message)
  80.         {
  81.             ScriptStream.Out.WriteLine(message);
  82.         }
  83.        
  84.         [Conditional("LOGGING")]
  85.         public static void PrintStack()
  86.         {
  87.             ScriptStream.PrintStackTrace();
  88.         }
  89.        
  90.         [Conditional("LOGGING")]
  91.         public static void PrintStack(Exception e)
  92.         {
  93.             ScriptStream.PrintStackTrace(e);
  94.         }
  95.        
  96.     }
  97.    
  98.     internal class AssertException : Exception
  99.     {
  100.         internal AssertException(string message) : base(message)
  101.         {
  102.         }
  103.     }
  104.    
  105.     internal class PreConditionException : AssertException
  106.     {
  107.         internal PreConditionException(string message) : base(message)
  108.         {
  109.         }
  110.     }
  111.    
  112.     internal class PostConditionException : AssertException
  113.     {
  114.         internal PostConditionException(string message) : base(message)
  115.         {
  116.         }
  117.     }
  118. }

Developer Fusion