Error Handling: Try And Catch
Published in
1 min readOct 22, 2018
In order to check your code for errors you can use the “try … catch … finally” syntax. This error handling tool is divided into 3 main blocks, and it can be implemented to monitor runtime errors that can be found within a valid code.
try {
// code to analyse
} catch(error) {
// code to execute if there's an error
} finally {
// code to execute either way
// whether there is an error or not
}
The catch
block can be used to alert a special message depending on the error you get. Each error object can have a few properties including: name
, message
, and stack
.
The throw
operator allows you to create your own errors.