EDDYMENS

Last updated 2023-03-03 00:19:11

What Is Exception Handling?

Table of contents

Definition

Exception handling is any piece of code you add to your software application to catch possible errors (expected or unexpected) within your software application.

Use Cases and Examples

Most often a software application will come to a halt or break if it encounters an error. For this reason software engineers [→] will add an exception handler that triggers a block of code to be run in case a software application stumbles on an error.

01: try { 02: const output = await fetch('https://url.tld'); 03: } catch (error) { 04: console.log('Error: ', error); 05: }

In the Javascript code above, the developer attempts to fetch some data from a URL within the try{...} in case that fails the developer provides code to be run which is within the catch(){..} block. In this case that is to output the error message.

Summary

Exception Handlers help to prevent software from breaking by at least ensuring the software fails gracefully in worse-case scenarios.

Here is another article you might like 😊 "Diary Of Insights: A Documentation Of My Discoveries"