# Panic! at the Golf Club [closed]

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:

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 a data-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("");}

• I don't think the separation you are making between types of errors is clear enough for this to work out. "No reasonable recovery strategy" would make me think that something that could be captured by a "try" block or similar structure shouldn't count, but of course most languages that define exceptions do it specifically to allow this behaviour. I find the large number of disagreements validating, so I'm going to vote to close this for now. Nov 23 '21 at 1:02
• Anything that can be captured as a "try" block counts as an exception, and thus the language has exceptions.
– Aly
Nov 23 '21 at 1:03
• @Aly Do you post to sandbox? Nov 23 '21 at 1:08
• I agree with FryAmTheEggman here. I think it is clear and unambiguous to differentiate between compiler errors and runtime errors (for languages that even have a compiler), and it's clear and unambiguous to distinguish between output to STDERR and STDOUT. But a lot of the other distinctions are super fuzzy. It seems that you are making some pretty big assumptions about language features, and on top of that your lists aren't exhaustive so there has to be a lot of guess work for what is left. Nov 23 '21 at 1:35
• To be clear I've closed this to prevent any further answers from piling up, there seems already to be some answers which are questionable, and the longer this stays open before being clarified the more cleanup that makes for moderators when it does get clarified. Once things are nice and clear I'd be glad to open it again. Nov 23 '21 at 1:50

# Motorola 6800 machine code, 2 1 byte

FD   HCF      ; halt and catch fire


From Some Guy:

It doesn’t really destroy the CPU, but makes it switch into a kind of debugging mode. Allegedly, HCF instruction on the 6800 should toggle the address lines in order very quickly. Legend added: up to the point that some support component might catch fire!

Fire would count as a panic, right?

# Jelly, 1 byte

s


Try it online!

I just tried random 1-letter commands until it worked.

# Vyxal, 1 byte

ḭ


Try it Online!

Because I forgot to make integer division account for division by 0.

## Better Explanation

Okay so normal division (/) accounts for division by 0 - it just always returns 0 (which has helpful uses for code golf). This is done in the overloads internally:

​def​ ​divide​(​lhs​, ​rhs​):
​    ​types​ ​=​ ​vy_type​(​lhs​), ​vy_type​(​rhs​)

​    ​def​ ​handle_numbers​(​lhs​, ​rhs​):
​        ​if​ ​rhs​ ​==​ ​0​:
​            ​return​ ​0
​        ​normal​, ​int_div​ ​=​ ​lhs​ ​/​ ​rhs​, ​lhs​ ​//​ ​rhs
​        ​return​ [​normal​, ​int_div​][​normal​ ​==​ ​int_div​]

​    ​return​ {
​        (​Number​, ​Number​): ​lambda​: ​handle_numbers​(​lhs​, ​rhs​),


That's taken directly from the vyxal source code btw.

Now the problem is that I never actually special cased division by 0 in the overloads for integer division:


​def​ ​integer_divide​(​lhs​, ​rhs​):
​    ​types​ ​=​ ​vy_type​(​lhs​), ​vy_type​(​rhs​)
​    ​return​ {
​        (​Number​, ​Number​): ​lambda​: ​lhs​ ​//​ ​rhs​,


As you can see, it just straight up tries to do python integer division without accounting for the special case normal division handles.

Also, just for clarification, if there aren't any inputs provided to a vyxal program, 0 is implicitly used.

## Alternate solutions

°


Try it Online!

How you gonna push the function reference of an undefined function?

←


Try it Online!

Same thing with variables

# C (clang), 9 bytes

f(){f();}


Try it online!

No exceptions in C, I hope a scary segfault with exit code is fine.

This isn't the shortest by any means, but here it is:

## C++ (g++), 14 bytes

main(){throw;}

• Are you sure that 1/0 is an exception or panic?
– BWG
Nov 23 '21 at 1:32
• On my system w/ gcc the compiler is too smart to fall for 1/0 :) So the shortest I could get was main(a){a/=!a;} and I knew someone would come up with something shorter for C. Nov 23 '21 at 1:35
• @BWG I would assume, but as I said, I'm not getting any output from it on my Linux machine, so maybe it is not... I'll mark it as a maybe-works answer. Nov 23 '21 at 12:37
• Hmm, looks like to make it be an exception you have to assign it: f=1/0; Nov 24 '21 at 0:05
• Never mind. I should have remembered that C++ won't let you drop the type specifier like C apparently does at places. Removing. Nov 24 '21 at 0:11

# JavaScript (V8), 3 bytes

0


Try it online!

# JavaScript (V8), 3 bytes

0()


Try it online!

Not sure if you can get it below 3.

• tio.run/##y0osSyxOLsosKNEts/j/X/P/fwA Nov 23 '21 at 0:50
• @LeakyNun Judging by the examples, I don't think SyntaxErrors are valid. Nov 23 '21 at 0:54
• "If your language does not have exceptions, then a panic is valid" Nov 23 '21 at 0:55
• A parse-time error is not a panic, as it happens before any code is run.
– Aly
Nov 23 '21 at 0:57
• Yeah but it is an exception. You only defined "panic" for languages without excceptions. Nov 23 '21 at 0:58

. $0  Try it online! Calls itself (well includes itself more accurately) until it segfaults. # Aubergine, 3 bytes ===  Try it online! As far as I know, all Aubergine programs have to be divisible by 3, since all instructions are 3 characters. There are lots of 3 character programs that will fail. Here's one that I think is aesthetically pleasing. :) # Ly, 1 byte I  Try it online! Tries to pop from an empty stack. There are other one character programs in Ly that will fail when there's nothing on the stack. • Any reason that just . (without the $0) shouldn't be considered an exception? I'm not familiar with how Bash handles errors.
– Aly
Nov 23 '21 at 1:01
• Running . does produce an error on TryItOnline, but I'm not sure it's panicky/exceptiony enough to qualify for this question? Nov 23 '21 at 1:07
• Ah, you'd be right: It doesn't halt execution of the rest of the program.
– Aly
Nov 23 '21 at 1:11
• By the way, this challenge is closed, but if you have multiple solutions, you should post multiple answers.
– user
Nov 23 '21 at 1:50
• Thanks! I've gotten conflicting guidance on posting multiple programs in one posting or as separate postings. So I'm not sure how to tell which way to go for a given question. Nov 23 '21 at 2:36

# !@#\$%^&*()_+, 3 bytes

^_@


Try it online!

Converts -1 to ascii but errors.

# Malbolge Unshackled, 0 bytes

Try it online!

I have no idea, don't ask me why it works.

• Things that do not count as panics: Compile time errors - I'd say error: not a valid Malbolge program counts as a sort of compile time error Nov 23 '21 at 0:57
• Why is this not a valid Malbolge program? As someone who has never written Malbolge, it seems like it should accept an empty tape just fine.
– Aly
Nov 23 '21 at 0:58
• @Aly The initial state of the memory depends on the last two characters of the program, so is undefined for shorter programs. Agreed, for what it's worth, that this is a compile-time error and thus invalid. Nov 24 '21 at 3:58