Stencil: Feature Request: Catch-All capability to catch errors at the component level.

Created on 9 Oct 2019  路  2Comments  路  Source: ionic-team/stencil

Stencil version:

 @stencil/core@latest

I'm submitting a:

[ ] bug report
[X] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
Whenever the developer wants to catch an error, we have to add try-catch blocks everywhere around the code in order to find issues.

Expected behavior:
Whenever an error happens in any part within the component, there should be a way to catch it by default and to do a custom error validation

import { Catch, Component, h } from '@stencil/core'
// Importing some custom error reporter that anyone has
import { reportError } from './myStuff';

@Component({
  tag: 'my-component'
})
export class MyComponent {
  @Catch
  _handleErrors(exception) {
    reportError(exception)
  }

  render() {
    return <div>Whatever</div>
  }
}

Steps to reproduce:

Related code:

// insert any relevant code here

Other information:

triage

Most helpful comment

@micheltobon What do you think about keeping consistency and define the function in this way componentDidCatch(error: Error): void as part of lifecycle?

All 2 comments

@micheltobon What do you think about keeping consistency and define the function in this way componentDidCatch(error: Error): void as part of lifecycle?

I think it works perfectly as well

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elmariofredo picture elmariofredo  路  3Comments

mitchellsimoens picture mitchellsimoens  路  3Comments

MatanYadaev picture MatanYadaev  路  3Comments

lcswillems picture lcswillems  路  3Comments

ryanmunger picture ryanmunger  路  3Comments