class MyError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, MyError.prototype)
}
}
const myFunction = () => {
throw new MyError('some reason');
}
try {
myFunction();
} catch (error) {
if (error instanceof MyError) {
// Handle MyError....
}
}