25
2
Inspired by I'm not the language you're looking for!
Challenge
Choose two different programming languages, and write a program that prints the following line to stdout (or equivalent):
This program errors out in <the current language> :P
and then generates different kind of error in each of the two languages.
Rules
Some rules are taken from the original challenge.
- In the output, language names should exactly follow:
- The name listed on TIO, optionally excluding the version number and/or the implementation name (e.g. if you use
JavaScript (Node.js)
as one of your languages, you can useJavaScript
for your language name, but notJS
orJavascript
.) - The full name on the official website (or GitHub repo) if your language of choice is not available on TIO.
- The name listed on TIO, optionally excluding the version number and/or the implementation name (e.g. if you use
- Neither program should take any input from the user.
- You may use comments in either language.
- Two different versions of the same language count as different languages.
- If this is done, the program should output the major version number, and if running on two different minor versions, should report the minor version also.
- You should not use prebuilt version functions (this includes variables that have already been evaluated at runtime).
- Two different command line flags in the same language also count as different languages as per this meta consensus, as long as the flags don't include code fragments (such as
-Dblahblah...
in C).- If this is done, the program should also output the flag used.
- Two errors are considered different unless both errors are generated by the same semantics (such as "division by zero", "segmentation fault", or "index out of range").
- If a language's runtime does not exit after an error, but reports the error in some way to the user, it's a valid error.
- If a language does not discriminate the error messages but has a known list of reasons that cause error, you must specify the reason, not the error message.
An example is><>
, which has only one error messagesomething smells fishy...
, but esolangs wiki page has a list of error reasons.
- Syntax error is not allowed unless it is generated by calling
eval()
or similar. - Throwing something manually (via
throw
(JS),raise
(Python),die
(Perl) or similar) is allowed, but all of them are considered as one kind of error. - Error by invalid command in 2D or golflangs is also allowed (and treated as one kind of error).
Examples
Python and Ruby
- Python:
This program errors out in Python :P
to stdout, then undefined identifier - Ruby:
This program errors out in Ruby :P
to stdout, then index out of bounds
C89 and C99
- C89:
This program errors out in C 89 :P
to stdout, then division by zero - C99:
This program errors out in C 99 :P
to stdout, then segmentation fault
Note that the version number should always be separated from the language name by a space.
Python 2.7.9 and Python 2.7.10
- Python 2.7.9:
This program errors out in Python 2.7.9 :P
to stdout, then syntax error on eval - Python 2.7.10:
This program errors out in Python 2.7.10 :P
to stdout, then key error on dict
Perl and Perl -n
- Perl:
This program errors out in Perl :P
to stdout, then invalid time format - Perl
-n
:This program errors out in Perl -n :P
to stdout, then try to open a file that doesn't exist
Winning condition
This is code-golf, so the shortest code in bytes wins. But you're always encouraged to post an answer that is fun or interesting even if it isn't very short.
Sandbox post (deleted) – Bubbler – 2018-03-21T04:58:58.767
Does the error need to halt the program? – Jo King – 2018-03-21T05:00:57.113
I initially thought so. However, if there are some languages that may continue (possibly with undefined behavior) after something like "division by zero", with some mechanism to acknowledge that the program encountered that error, then I will happily allow that. – Bubbler – 2018-03-21T05:12:54.487
I think I already know the answer, but just in case: may the sentence
This program errors out in ...
contain mixed tabs/spaces instead of just spaces? – Kevin Cruijssen – 2018-03-21T09:08:33.103Related (print two different texts in two different languages). – Kevin Cruijssen – 2018-03-21T10:13:06.457
Can there be trailing/leading whitespace printed as well? – Conor O'Brien – 2018-03-21T14:21:48.803
Can the language names in the output be generated from built-in functions? – Tom Carpenter – 2018-03-21T17:43:37.973
What about languages that are too old to have an official website or GitHub repository? – Mark – 2018-03-21T22:09:50.143
@KevinCruijssen Spaces only. – Bubbler – 2018-03-21T23:00:50.217
@ConorO'Brien Optional trailing newline is OK, everything else is not. – Bubbler – 2018-03-21T23:01:41.533
@TomCarpenter It's fine, as long as it fits the format. – Bubbler – 2018-03-21T23:02:11.467
@Mark I'll ask it on meta. That may be a future reference for any other challenges that want to involve the language name in some way. – Bubbler – 2018-03-21T23:11:41.767
@Mark had that exact case in my submission, I used what I considered "canonical" names with links to some informational websites -- hope this is fine. – Felix Palmen – 2018-03-22T08:27:37.383
Can we output to stderr? It is a default output method
– Logern – 2018-10-22T04:21:51.530