ExceptionTestBoundObject.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using CefSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace UAS_Web.tool
  9. {
  10. class ExceptionTestBoundObject
  11. {
  12. [DebuggerStepThrough]
  13. private double DivisionByZero(int zero)
  14. {
  15. return 10 / zero;
  16. }
  17. [DebuggerStepThrough]
  18. public double TriggerNestedExceptions()
  19. {
  20. try
  21. {
  22. try
  23. {
  24. return DivisionByZero(0);
  25. }
  26. catch (Exception innerException)
  27. {
  28. throw new InvalidOperationException("Nested Exception Invalid", innerException);
  29. }
  30. }
  31. catch (Exception e)
  32. {
  33. throw new OperationCanceledException("Nested Exception Canceled", e);
  34. }
  35. }
  36. [DebuggerStepThrough]
  37. public int TriggerParameterException(int parameter)
  38. {
  39. return parameter;
  40. }
  41. public void TestCallbackException(IJavascriptCallback errorCallback, IJavascriptCallback errorCallbackResult)
  42. {
  43. const int taskDelay = 500;
  44. //Task.Run(async () =>
  45. //{
  46. // await TaskEx.Delay(taskDelay);
  47. // using (errorCallback)
  48. // {
  49. // JavascriptResponse result = await errorCallback.ExecuteAsync("This callback from C# was delayed " + taskDelay + "ms");
  50. // string resultMessage;
  51. // if (result.Success)
  52. // {
  53. // resultMessage = "Fatal: No Exception thrown in error callback";
  54. // }
  55. // else
  56. // {
  57. // resultMessage = "Exception Thrown: " + result.Message;
  58. // }
  59. // await errorCallbackResult.ExecuteAsync(resultMessage);
  60. // }
  61. //});
  62. }
  63. }
  64. }