It is called when the component throws an error in one of it’s call back methods.
Error is a JavaScript native error object, stack argument is a string.
childComponent.html
<template>
childcomponent
</template>
childComponent.js
import { LightningElement} from 'lwc';
export default class ChildComponent extends LightningElement {
constructor(){
super();
console.log('Yes I am in child constructor');
throw 'This is the custom error message from child component';
}
errorCallback(error,stack){
alert('error'+error);
alert('stack'+stack);
}
}
parentComponent.html
<template>
<c-child-component>
</c-child-component>
</template>
parentComponent.js
import { LightningElement,api } from 'lwc';
export default class ParentComponent7 extends LightningElement {
constructor(){
super();
console.log('Yes I am in parent constructor');
}
errorCallback(error,stack){
alert('error'+error);
alert('stack'+stack);
}
}
LightningApplication
<aura:application>
<c:parentComponent>
</c:parentComponent>
</aura:application>
output:
errorThis is the custom error message from child component
stack<c-parent-component> <c-child-component>
Comments
Post a Comment