I was pondering today about how many characters it would take in each language to throw an exception, and noticed there wasn't any existing collection of answers, so:
The task
Throw an exception in the least amount of characters. If your language does not have exceptions, then a panic is valid. A panic constitutes as anything that there is no reasonable recovery strategy for. Examples include (but are not limited to):
- Explicit
panic
instructions - Memory accesses that will always fail
- Integer division by zero
- Taking the
head
of an empty list in adata
-based language
Things that do not count as panics:
- Compile-/parse-time errors (such as syntax errors and invalid types in a statically-typed language)
- Unbound/undefined identifier errors
- Quoting/splicing errors that are not the result of runtime data (ex
#'a
in Lisp is truly an unbound identifier error)
Examples:
Scala (.sc): 3 Characters
???
Scala 3 (.scala): 16 Characters
@main def a= ???
Python: 3 Characters
1/0
Zig: 28 Characters
pub fn main()u8{@panic("");}