示例#1
0
 static void DefaultNoExceptionShielding()
 {
     Console.WriteLine("Getting salary for 'jsmith'...");
     Console.WriteLine();
     SalaryCalculator calc = new SalaryCalculator();
     Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
 }
示例#2
0
        static void DefaultNoExceptionShielding()
        {
            Console.WriteLine("Getting salary for 'jsmith'...");
            Console.WriteLine();
            SalaryCalculator calc = new SalaryCalculator();

            Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
        }
示例#3
0
        static void ProvidingAdminAssistance()
        {
            Console.WriteLine("Getting salary for 'jsmith'...");
            Console.WriteLine();
            // NOTE: Any exception raised when creating the SalaryCalculator
            // class instance will not be handled using this approach.
            SalaryCalculator calc   = new SalaryCalculator();
            decimal          result = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "AssistingAdministrators");

            Console.WriteLine("Result is: {0}", result);
        }
示例#4
0
 static void LoggingTheException()
 {
     try
     {
         Console.WriteLine("Getting salary for 'jsmith'...");
         Console.WriteLine();
         // NOTE: Any exception raised when creating the SalaryCalculator
         // class instance will not be handled using this approach.
         var     calc   = new SalaryCalculator();
         decimal result = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "LoggingAndReplacingException");
         Console.WriteLine("Result is: {0}", result);
     }
     catch (Exception ex)
     {
         MenuOption.ShowExceptionDetails(ex);
         Console.WriteLine("Open the Windows Application Event Log to see the logged exception details.");
     }
 }
示例#5
0
        static void WithWrapExceptionShieldingStatic()
        {
            Console.WriteLine("Getting salary for 'jsmith'...");
            Console.WriteLine();

            // NOTE: Any exception raised when creating the SalaryCalculator
            // class instance will not be handled using this approach.
            SalaryCalculator calc   = new SalaryCalculator();
            decimal          result = 0;

            try
            {
                result = calc.GetWeeklySalary("jsmith", 0);
            }
            catch (Exception ex)
            {
                Exception exceptionToThrow;
                if (ExceptionPolicy.HandleException(ex, "ExceptionShielding", out exceptionToThrow))
                {
                    if (exceptionToThrow == null)
                    {
                        throw;
                    }
                    else
                    {
                        throw exceptionToThrow;
                    }
                }
            }
            Console.WriteLine("Result is: {0}", result);
            // NOTE: If you do not need to return the value from the function, you can
            // simply consume it within the lambda expression. This is a simple example:
            // ------------------------------
            //exManager.Process(() =>
            //  {
            //    SalaryCalculator calc = new SalaryCalculator();
            //    Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
            //  },
            //  "ExceptionShielding");
            // ------------------------------
            // This approach also allows you to handle any exception raised by creating the
            // instance of the SalaryCalculator class.
        }
示例#6
0
        static void WithWrapExceptionShielding()
        {
            Console.WriteLine("Getting salary for 'jsmith'...");
            Console.WriteLine();
            // NOTE: Any exception raised when creating the SalaryCalculator
            // class instance will not be handled using this approach.
            SalaryCalculator calc = new SalaryCalculator();
            var result            = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "ExceptionShielding");

            Console.WriteLine("Result is: {0}", result);
            // NOTE: If you do not need to return the value from the function, you can
            // simply consume it within the lambda expression. This is a simple example:
            // ------------------------------
            //exManager.Process(() =>
            //  {
            //    SalaryCalculator calc = new SalaryCalculator();
            //    Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
            //  },
            //  "ExceptionShielding");
            // ------------------------------
            // This approach also allows you to handle any exception raised by creating the
            // instance of the SalaryCalculator class.
        }
示例#7
0
 static void WithWrapExceptionShielding()
 {
     Console.WriteLine("Getting salary for 'jsmith'...");
     Console.WriteLine();
     // NOTE: Any exception raised when creating the SalaryCalculator
     // class instance will not be handled using this approach.
     SalaryCalculator calc = new SalaryCalculator();
     var result = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "ExceptionShielding");
     Console.WriteLine("Result is: {0}", result);
     // NOTE: If you do not need to return the value from the function, you can
     // simply consume it within the lambda expression. This is a simple example:
     // ------------------------------
     //exManager.Process(() =>
     //  {
     //    SalaryCalculator calc = new SalaryCalculator();
     //    Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
     //  },
     //  "ExceptionShielding");
     // ------------------------------
     // This approach also allows you to handle any exception raised by creating the
     // instance of the SalaryCalculator class.
 }
示例#8
0
 static void WithReplaceExceptionShielding()
 {
     Console.WriteLine("Getting salary for 'jsmith'...");
     Console.WriteLine();
     // NOTE: Any exception raised when creating the SalaryCalculator
     // class instance will not be handled using this approach.
     SalaryCalculator calc = new SalaryCalculator();
     decimal result = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "ReplacingException");
     Console.WriteLine("Result is: {0}", result);
 }
示例#9
0
 static void LoggingTheException()
 {
     try
     {
         Console.WriteLine("Getting salary for 'jsmith'...");
         Console.WriteLine();
         // NOTE: Any exception raised when creating the SalaryCalculator
         // class instance will not be handled using this approach.
         var calc = new SalaryCalculator();
         decimal result = exManager.Process(() => calc.GetWeeklySalary("jsmith", 0), "LoggingAndReplacingException");
         Console.WriteLine("Result is: {0}", result);
     }
     catch (Exception ex)
     {
         MenuOption.ShowExceptionDetails(ex);
         Console.WriteLine("Open the Windows Application Event Log to see the logged exception details.");
     }
 }
示例#10
0
    static void WithWrapExceptionShieldingStatic()
    {
      Console.WriteLine("Getting salary for 'jsmith'...");
      Console.WriteLine();

      // NOTE: Any exception raised when creating the SalaryCalculator
      // class instance will not be handled using this approach.
      SalaryCalculator calc = new SalaryCalculator();
      decimal result = 0;
      try
      {
        result = calc.GetWeeklySalary("jsmith", 0);
      }
      catch (Exception ex)
      {
        Exception exceptionToThrow;
        if (ExceptionPolicy.HandleException(ex, "ExceptionShielding", out exceptionToThrow))
        {
          if (exceptionToThrow == null)
            throw;
          else
            throw exceptionToThrow;
        }
      }
      Console.WriteLine("Result is: {0}", result);
      // NOTE: If you do not need to return the value from the function, you can
      // simply consume it within the lambda expression. This is a simple example:
      // ------------------------------
      //exManager.Process(() =>
      //  {
      //    SalaryCalculator calc = new SalaryCalculator();
      //    Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 0));
      //  },
      //  "ExceptionShielding");
      // ------------------------------
      // This approach also allows you to handle any exception raised by creating the 
      // instance of the SalaryCalculator class.
    }