Skip to content

Instantly share code, notes, and snippets.

@wesleyduff
Last active June 12, 2018 16:58
Show Gist options
  • Save wesleyduff/82be89c5e4c907ef4ca70c41db563200 to your computer and use it in GitHub Desktop.
Save wesleyduff/82be89c5e4c907ef4ca70c41db563200 to your computer and use it in GitHub Desktop.
Separate Error Handling from your code : Clean Code : Error Handling
class CustomException extends Error {
constructor(message, errorCode) {
super(message);
this.name = 'MyError';
this.code = errorCode || 510;
}
}
class Logger {
constructor(error){
this.error = error;
console.log(`${error.message}, : ${error.name}, : ${error.code}`)
}
}
class RunMethods {
static run(){
try{
throw new CustomException('this is my custom error', 520)
} catch(e){
new Logger(e);
}
}
static runTwo(){
try{
throw new CustomException('this is my custom error part 2')
} catch(e){
new Logger(e);
}
}
}
console.log('Run your code without having to manage error handling within your method calls.')
RunMethods.run();
RunMethods.runTwo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment