Computer ScienceProgrammingMedium

Exception Handling

Also known as:error handlingexception managementfault handling

Exception handling is a programming mechanism that detects, manages, and responds to runtime errors (exceptions) in a structured way, preventing a program from crashing unexpectedly. Using constructs such as try, catch, finally, and throw, developers can intercept errors, execute recovery logic, release resources, and propagate meaningful error messages. Proper exception handling improves software robustness, user experience, and makes debugging easier by separating error-handling code from normal program flow.

Exception Handling Keywords Across Languages

Keyword / BlockPurposeJavaPythonJavaScript
Try blockContains code that may throwtry {}try:try {}
Catch / ExceptHandles a specific exceptioncatch(Exception e) {}except ValueError:catch(e) {}
Finally / ElseAlways executes (cleanup)finally {}finally:finally {}
Throw / RaiseManually trigger an exceptionthrow new Exception()raise ValueError()throw new Error()
Custom exceptionUser-defined exception classextends Exceptionclass MyError(Exception)extends Error

Interactive Tools

W3Schools – Java Exception Handling

Open Tool

Codecademy – Error Handling in Python

Open Tool

Khan Academy – Error Handling Basics

Open Tool
Flowchart showing program flow through try-catch-finally blocks during exception handling

Wikimedia Commons, CC BY-SA

Related Terms

From Latin "exceptio" meaning "an exception" or "exclusion", derived from "excipere" (to take out). In programming, the concept was introduced in PL/I (1964) and later formalized in CLU (1975) by Barbara Liskov. The try-catch-finally pattern was popularised by C++ (1990) and Java (1995).

exception-handlingerror-handlingtry-catchruntime-errorsrobustness