|
93 | 93 | LogMessage("Invoked DoAsyncWorkParamsReturn, return value: message=" + retValue.Message + ", value=" + retValue.Value); |
94 | 94 | } |
95 | 95 |
|
| 96 | + // Demo functions to test exception handling |
| 97 | + async function InvokeThrowException() { |
| 98 | + LogMessage("Invoking ThrowException"); |
| 99 | + try { |
| 100 | + await window.HybridWebView.InvokeDotNet('ThrowException'); |
| 101 | + LogMessage("ThrowException unexpectedly succeeded!"); |
| 102 | + } catch (ex) { |
| 103 | + LogMessage("Caught exception from ThrowException: " + ex.message); |
| 104 | + LogMessage("Exception type: " + (ex.dotNetErrorType || "Unknown")); |
| 105 | + if (ex.dotNetStackTrace) { |
| 106 | + LogMessage("Stack trace: " + ex.dotNetStackTrace.substring(0, 200) + "..."); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + async function InvokeThrowExceptionAsync() { |
| 112 | + LogMessage("Invoking ThrowExceptionAsync"); |
| 113 | + try { |
| 114 | + const result = await window.HybridWebView.InvokeDotNet('ThrowExceptionAsync'); |
| 115 | + LogMessage("ThrowExceptionAsync unexpectedly succeeded with result: " + result); |
| 116 | + } catch (ex) { |
| 117 | + LogMessage("Caught async exception from ThrowExceptionAsync: " + ex.message); |
| 118 | + LogMessage("Exception type: " + (ex.dotNetErrorType || "Unknown")); |
| 119 | + } |
| 120 | + } |
| 121 | + |
96 | 122 | </script> |
97 | 123 | </head> |
98 | 124 | <body> |
|
114 | 140 | <button onclick="InvokeDoAsyncWorkReturn()">Call C# async method (no params) and get simple return value</button> |
115 | 141 | <button onclick="InvokeDoAsyncWorkParamsReturn()">Call C# async method (params) and get complex return value</button> |
116 | 142 | </div> |
| 143 | + <div> |
| 144 | + <strong>Exception Handling Tests:</strong> |
| 145 | + <button onclick="InvokeThrowException()">Test C# Exception Handling</button> |
| 146 | + <button onclick="InvokeThrowExceptionAsync()">Test C# Async Exception Handling</button> |
| 147 | + </div> |
117 | 148 | <div> |
118 | 149 | Log: <textarea readonly id="messageLog" style="width: 80%; height: 10em;"></textarea> |
119 | 150 | </div> |
|
0 commit comments