static void DefaultNoExceptionShielding() { Console.WriteLine("Getting salary for 'jsmith'..."); Console.WriteLine(); SalaryCalculator calc = new SalaryCalculator(); Console.WriteLine("Result is: {0}", calc.GetWeeklySalary("jsmith", 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)); }
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); }
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."); } }
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. }
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. }
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. }
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); }
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."); } }
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. }