示例#1
0
        private void notifyUserButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                StringBuilder sb = new StringBuilder();

                sb.Append("Scenario: Notify the user when an exception occurs");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("1. An exception occurs and is detected in the Business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("2. The Business layer specifies the \"Notify Policy\" as the exception handling policy.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("3. The \"Notify Policy\" is configured to first log the exception, then replace the exception with a new one, and finally return to the application by recommending a rethrow.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("4. The exception is propagated to and caught by the UI layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("5. The UI layer catches the exception and calls the \"Global Policy\", which displays the exception in a message box.");
                sb.Append(Environment.NewLine);
                DisplayScenarioStart(sb.ToString());

                AppService svc = new AppService();

                svc.ProcessAndNotify();

                Cursor = System.Windows.Forms.Cursors.Arrow;
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }
示例#2
0
        private void replaceExceptionButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                StringBuilder sb = new StringBuilder();

                sb.Append("Scenario: Replace the original exception with another before propagating");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("1. UI layer calls into business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("2. A SecurityException exception occurs and is detected in the business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("3. The business layer specifies the \"Replace Policy\" as the exception handling policy.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("4. The \"Replace Policy\" is configured to use a replace handler to replace the original exception with an ApplicationException exception.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("5. The rethrowAction is set to \"Throw\", resulting in the new exception being thrown by the block upon completion of the handler chain execution.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("6. The new exception is caught and displayed.");

                DisplayScenarioStart(sb.ToString());
                AppService svc = new AppService();

                svc.ProcessWithReplace();
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }
示例#3
0
        private void suppressExceptionButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                StringBuilder sb = new StringBuilder();

                sb.Append("Scenario: Process and resume execution");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("1. UI layer calls into business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("2. A SecurityException occurs and is detected in the business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("3. The business layer specifies the \"Handle and Resume Policy\" as the exception handling policy.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("4. The \"Handle and Resume Policy\" is configured with a rethrowAction of \"None\", resulting in execution being resumed upon completion of the handler chain execution.");

                DisplayScenarioStart(sb.ToString());

                AppService svc = new AppService();

                svc.ProcessAndResume();

                this.resultsTextBox.Text += "Exception processed, execution resumed.";

                Cursor = System.Windows.Forms.Cursors.Default;
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }
示例#4
0
        private void propagateOriginalExceptionButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                StringBuilder sb = new StringBuilder();

                sb.Append("Scenario: Propagate original exception");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("1. UI layer calls into business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("2. A System.Exception occurs and is detected in the business layer.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("3. The business layer specifies the \"Propagate Policy\" as the exception handling policy.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("4. The \"Propagate Policy\" is configured to recommend a rethrow upon return from processing the exception handlers.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("5. Control is returned to the business layer, which rethrows the original exception.");
                sb.Append(Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("6. The original exception is caught and displayed.");

                DisplayScenarioStart(sb.ToString());

                AppService svc = new AppService();

                svc.ProcessWithPropagate();
            }
            catch (Exception ex)
            {
                ProcessUnhandledException(ex);
            }
        }