mirror of https://github.com/sveltejs/svelte
Rather than _always_ adding a try/catch this adds a try/catch only when on_error is present. Doesn't currently work because apparently updates and initial renders go through different paths. Also because I need maintainer support to figure this out...pull/3587/head
parent
14a46a17d0
commit
1135336e88
@ -0,0 +1,7 @@
|
|||||||
|
export default {
|
||||||
|
test({ assert, target }) {
|
||||||
|
const div = target.querySelector('div');
|
||||||
|
|
||||||
|
assert.equal('error', div.className);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
export default {};
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import { onError } from 'svelte';
|
||||||
|
let error;
|
||||||
|
onError(err => {
|
||||||
|
error = err;
|
||||||
|
});
|
||||||
|
function getWidget() {
|
||||||
|
throw new Error('Oops');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<div class='error'>{error.message}</div>
|
||||||
|
{:else}
|
||||||
|
<div class='success'>{getWidget()}</div>
|
||||||
|
{/if}
|
Loading…
Reference in new issue