I have a class, I would like an error method to return a way to handle it from the object
class MyClass {
On(value){
try{
throw new Error("Massimo due candidati");
}
catch(e){
console.log(e.name, e.message); //Error, I'm Evil
}
}
}
If I create an object of the class how can I handle the error in a similar way?
var obj = new MyClass();
obj.on(value, err=> {
if (err) {
onError(err.message);
}else{
console.log("Inserimento ok");
}
});
Thanks for your attention.