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.
| Keyword / Block | Purpose | Java | Python | JavaScript |
|---|---|---|---|---|
| Try block | Contains code that may throw | try {} | try: | try {} |
| Catch / Except | Handles a specific exception | catch(Exception e) {} | except ValueError: | catch(e) {} |
| Finally / Else | Always executes (cleanup) | finally {} | finally: | finally {} |
| Throw / Raise | Manually trigger an exception | throw new Exception() | raise ValueError() | throw new Error() |
| Custom exception | User-defined exception class | extends Exception | class MyError(Exception) | extends Error |
Wikimedia Commons, CC BY-SA
Object-Oriented Programming (OOP) is a programming paradigm that organises software design around data, called objects, rather than functions and logic. Each object encapsulates data (attributes) and behaviour (methods), and objects interact with one another to build complex systems. The four core principles of OOP — encapsulation, inheritance, polymorphism, and abstraction — promote code reusability, modularity, and maintainability.
A class in object-oriented programming is a blueprint or template that defines the attributes (data fields) and methods (functions) common to all objects of that type. When a class is instantiated, it produces an object — a concrete instance that holds its own copy of the class's attributes. Classes enable code organisation by grouping related data and behaviour together, forming the foundational building blocks of OOP design.
Abstraction in OOP is the principle of exposing only the essential features of an object to the outside world while hiding the complex implementation details. It is achieved through abstract classes and interfaces, which define a contract specifying what methods a class must implement without dictating how they are implemented. Abstraction reduces complexity for the programmer using the class and allows internal implementations to change without affecting dependent code.
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).