An exception is an event occurs when something unusual happens, specifically something that the code isn’t programmed to do.
Exception is actually a shorthand for exceptional event!
Most programming languages offer ways to raise (cause an) exceptions, as a form of defensive programming, as well as catch them. Exception handling is the coding practice of ensure a program attempts to achieve it’s defined purpose even when an exception occurs, such as by changing some variables or having limited functionality (instead of straight up crashing).
Runtime Exceptions
In most cases, an exception occurs during runtime only, since anything that fails to compile is just a compile-time error, not an exception*.
*Java, of course, is a weird freaky language and allows compiled exceptions. See below.
Checked Exceptions
However, compile-time exceptions, also known as checked exceptions are a feature of Java.