DEV Community

Cover image for Clean Code Applied to JavaScript — Part V. Exceptions

Clean Code Applied to JavaScript — Part V. Exceptions

Carlos Caballero on December 19, 2019

Introduction The exceptions are an essential piece in the development of quality software since we will be controlling unexpected or non...
Collapse
 
bybruno profile image
Bruno A.

Wow!! What an amazing post. Many programmers should see this.

It's very common for me to get projects that programmers don't handle errors well.

This post will help me give direction to new developers on my team, thanks so much for sharing!

Collapse
 
carlillo profile image
Carlos Caballero

Thanks Bruno!

I'm writing a post series in which I'm summarize many tips that I've taught for years 🙃

Collapse
 
briancodes profile image
Brian • Edited

I rarely use or throw custom exceptions, but I'm going to look into it more now

I was wondering if Typescript supports a update(): Account throws UpdateException {...} style syntax. It's been suggested, but not supported yet:
github.com/microsoft/TypeScript/is...

Collapse
 
devhammed profile image
Hammed Oyedele

Great post ✌️✌️✌️,
I have been using a technique for handling errors...I would alert (Material UI Modal) the user showing the error message with a retry action button...it has been working for me so far, do you have a better approach?

Collapse
 
coly010 profile image
Colum Ferry

Awesome post, it may be worth noting that there is a change coming to the spec that allows developers to ignore the specifics of the error, and do whatever they want in the catch:

try {
  someThrowableMethod();
} catch {
  uhOhTellUserWeErrored();
}

We no longer have to ask the engine what the error was, and instead just react to it.

This change has landed yet, but it's on its way!

Again, great article!

Collapse
 
blarzhernandez profile image
Roberto Hernandez

Thanks Carlos. Great and helpful post!