Make an error quine!
Windows Command Prompt
& was unexpected at this time.
Ed (1 byte)
All the other solutions thus far are long and ugly. I suppose that is because of the nature of most error messages. But a good error message is elegant in its simplicity. For that, look no further than ed.
?
Save this to a file called edscript
and run with ed < edscript
, or run ed<<<?
. The result:
?
The question mark is written to stderr and ed returns 1, so this actually is an error message. I wonder why ed isn't very popular?
False (0 bytes)
Run with false filename
. It writes the program's source code (i.e. nothing) to stderr and returns 1. Of course, calling false a programming language is questionable, and the zero byte quine is unoriginal, but I thought I might as well add it. There is probably some interpreter for a language that prints no error messages, and could replace false.
Now I wish this was code golf.
CoffeeScript, syntactically valid
As tested on their website using Chrome or Firefox.
ReferenceError: defined is not defined
You can replace defined
with anything that's not a built-in variable, but I thought this version was fun. Unfortunately, undefined is not defined
in particular doesn't work as a quine.
In CoffeeScript this isn't even a syntax error, because it compiles. This is technically a runtime error in JavaScript, albeit a boring one. CoffeeScript is a likely candidate to produce some more interesting runtime error quines because a lot of funny sentences are valid code. E.g. the above example compiles to
({
ReferenceError: defined === !defined
});