|
1 | | -<h1>Welcome to SvelteKit</h1> |
2 | | -<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p> |
3 | | - |
4 | 1 | <script> |
5 | | - const badVariable = () => { |
6 | | - return fakeVariable; |
7 | | - } |
8 | | - badVariable(); |
| 2 | + import { Exceptionless } from "@exceptionless/browser"; |
| 3 | +
|
| 4 | + let message = null; |
| 5 | + let errorInfo = null; |
| 6 | +
|
| 7 | + async function submitMessage() { |
| 8 | + await Exceptionless.submitLog("Hello, world!"); |
| 9 | + errorInfo = null; |
| 10 | + message = "Hello, world!"; |
| 11 | + }; |
| 12 | +
|
| 13 | + async function tryCatchExample() { |
| 14 | + try { |
| 15 | + throw new Error("Caught in the try/catch"); |
| 16 | + } catch (error) { |
| 17 | + message = null; |
| 18 | + errorInfo = error.message; |
| 19 | + await Exceptionless.submitException(error); |
| 20 | + } |
| 21 | + }; |
| 22 | +
|
| 23 | + function unhandledExceptionExample() { |
| 24 | + throw new Error("Unhandled exception"); |
| 25 | + }; |
9 | 26 | </script> |
| 27 | + |
| 28 | +<div class="App"> |
| 29 | + <header class="App-header"> |
| 30 | + <div class="container"> |
| 31 | + <h1 class="App-title">Exceptionless Svelte Sample</h1> |
| 32 | + <div> |
| 33 | + <p> |
| 34 | + Throw an uncaught error and make sure Exceptionless tracks it. |
| 35 | + </p> |
| 36 | + <button on:click={unhandledExceptionExample}> |
| 37 | + Throw unhandled error |
| 38 | + </button> |
| 39 | + </div> |
| 40 | + <p> |
| 41 | + The following buttons simulated handled events outside the |
| 42 | + component. |
| 43 | + </p> |
| 44 | + <button on:click={submitMessage}>Submit Message</button> |
| 45 | + {#if message} |
| 46 | + <p> |
| 47 | + Message sent to Exceptionless:{" "} |
| 48 | + <code>{message}</code> |
| 49 | + </p> |
| 50 | + {/if} |
| 51 | + <button on:click={tryCatchExample}>Try/Catch Example</button> |
| 52 | + {#if errorInfo} |
| 53 | + <p> |
| 54 | + Error message sent to Exceptionless:{" "} |
| 55 | + <code>{errorInfo}</code> |
| 56 | + </p> |
| 57 | + {/if} |
| 58 | + </div> |
| 59 | + </header> |
| 60 | +</div> |
| 61 | + |
| 62 | +<style> |
| 63 | +.App { |
| 64 | + text-align: center; |
| 65 | +} |
| 66 | +
|
| 67 | +.App-header { |
| 68 | + background-color: #282c34; |
| 69 | + min-height: 100vh; |
| 70 | + display: flex; |
| 71 | + flex-direction: column; |
| 72 | + align-items: center; |
| 73 | + justify-content: center; |
| 74 | + font-size: calc(10px + 2vmin); |
| 75 | + color: white; |
| 76 | +} |
| 77 | +
|
| 78 | +.container { |
| 79 | + max-width: 85%; |
| 80 | + margin: auto; |
| 81 | +} |
| 82 | +</style> |
0 commit comments