exception
An exception is the program's signal that an unexpected situation has arisen during execution, preventing it from continuing its work via the usual path.
In plain terms
Imagine a baker working according to the usual recipe, and suddenly the flour runs out. They do not continue baking as if nothing happened, but stop and tell the shift supervisor. In the world of programs, this 'telling' is the exception: the program signals that something deviates from the plan.
An exception serves to ensure errors do not remain hidden. The program does not continue calculating with bad data but halts work and hands the issue over to a code section written for this specific case. This is exception handling.
If no one is prepared for the situation, the exception remains "unhandled," and the program stops. In such cases, you see an error message or a crashing application.
It comes up daily in the work of AI agents, too. A coding agent runs the program, reads the exception text, and works out from it what needs to be fixed.
How it works
- The program encounters an obstacle during an operation: for example, it cannot find the file, the network disconnects, or it needs to divide by zero.
- At this point, it throws an exception: it creates a small package describing the type of error, its text, and the exact location in the code where it occurred.
- Normal execution is interrupted, and the exception propagates backward along the call stack the program used to reach that point.
- If it encounters code along the way that 'catches' this type of exception, it handles the situation: retries, chooses another path, or displays a clear message.
- If no one catches it, the program stops and outputs the location and path of the error; this list is called a stack trace.
An everyday example
You open an app on your phone, tap a button, and the app closes silently. Behind the scenes, an unhandled exception likely occurred. If instead you see 'No internet connection, try again', the developer prepared for the situation and the program caught the exception.
Who is affected
A common misconception
Limits and risks
- An exception only signals the error that the program detects: a bad but formally valid result does not trigger an exception.
- If the code catches the exception but does nothing with it, the error becomes invisible and much harder to find later.
- The raw error message may contain sensitive data, such as a file path or database name, so it should not be shown to the user.
- A coding agent may be prone to 'fixing' a bug by simply suppressing the exception, so it is worth checking whether the root cause has truly been resolved.
Similar, but not the same
- programhiba (bug) – A bug is an error in the code, while an exception is a runtime signal that can be triggered by a bug but also by a broken internet connection.
- crash – A crash is the program stopping; an exception leads to this only if no one handles it.
- error code – The program returns the error code, and the caller must check it separately, while the exception automatically halts execution, making it harder to ignore.
Related concepts
error handling, programming language, control structure
unhandled exception, timeout
runtime error, programhiba, debugging, stack dump, logging, collapse
A brief history
The concept of exception handling emerged in the 1960s; one early implementation was in the PL/I language introduced in 1964. The now-familiar 'try-catch' form developed in the 1970s (for example, in the CLU language) and became widespread through C++, Java, and Python. Keywords vary by language: most use try–catch, while Python uses try–except.
Where things stand
As of late 2026, it is a basic tool in most widely used programming languages, although some newer languages (such as Go and Rust) deliberately chose a different approach to error handling. Coding agents read the exception messages and fix many of the errors on their own.
In the news
- OpenAI releases GPT-6.1 Terra, which it says is strong at computer useOct 26, 2026 · Agent Age
- Agentic AI moves supply chain exception management from forecasting to actionSep 30, 2026 · Ipar
- Anthropic and OpenAI ask Australia to ease its ban on AI training with local contentSep 22, 2026 · Jog
- Petition for Hungarian authors calls for labelling AI-written text and debate turns to the right to say noSep 1, 2026 · Jog
- Samsung's Göd battery plant shows its operations to the public in a rare exceptionAug 31, 2026 · Ipar
- After a major win, some lawyers back litigants who use AI in courtAug 17, 2026 · Jog
Also known as
exception · exception · exception handling · exception handling · unhandled exception · unhandled exception · throws an exception · try-catch
Sources
This entry was machine-edited and has undergone machine expert review; the “In the news” section updates automatically from Agent Age stories.