/// <summary /> public Task <MethodOneResponse> InnerRun(MethodOneRequest request) { /* * Handled exception */ if (request.Value > 100) { SampleException iex = new SampleException(ER.One_Error1, "V1"); throw new SampleException(ER.One_Error2, iex, "V2", "V3"); } /* * Unhandled exception */ if (request.Value > 10) { throw new Exception("oops"); } /* * Normal behavior */ return(Task.FromResult(new MethodOneResponse() { Value = request.Value * 10 })); }
public void PopulatesPropertiesFromException() { Exception inner = new Exception("Foo"); PopulateStackTrace(inner); SampleException outer = new SampleException("Bar", inner) { Prop1 = "Value1", Prop2 = "Value2" }; PopulateStackTrace(outer); ExceptionData outerData = new ExceptionData(outer); Assert.AreEqual(outer.GetType().FullName, outerData.Type); Assert.AreEqual(outer.Message, outerData.Message); Assert.AreEqual(new PropertySet() { { "Prop1", "Value1" }, { "Prop2", "Value2" } }, outerData.Properties); Assert.AreEqual(outer.StackTrace, outerData.StackTrace.ToString()); Assert.IsNotNull(outerData.InnerException); ExceptionData innerData = outerData.InnerException; Assert.AreEqual(inner.GetType().FullName, innerData.Type); Assert.AreEqual(inner.Message, innerData.Message); Assert.AreEqual(inner.StackTrace, innerData.StackTrace.ToString()); Assert.IsNull(innerData.InnerException); }
private static void ExceptionHandling() { var exception = new SampleException(); exception.Exception(); }
/// <summary> /// Displays sample exceptions to the user /// </summary> /// <param name="e">The exception that was thrown</param> /// <param name="Type">Extra information on how to handle the exception</param> public void HandleSampleException(SampleException e, ApplicationMessage Type) { // Build a message to display to the user string strMsg = string.Empty; if (e != null) strMsg = e.Message; if (ApplicationMessage.ApplicationMustExit == Type) { strMsg += "\n\nThis sample will now exit."; System.Windows.Forms.MessageBox.Show(strMsg, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); // Close the window, which shuts down the app if (this.IsHandleCreated) this.Close(); } else { if (ApplicationMessage.WarnSwitchToRef == Type) strMsg = "\n\nSwitching to the reference rasterizer,\n"; strMsg += "a software device that implements the entire\n"; strMsg += "Direct3D feature set, but runs very slowly."; System.Windows.Forms.MessageBox.Show(strMsg, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } }