0
\$\begingroup\$

Hopefully not duplicate, but I did not find one.

Challenge

The challenge is to write full program, which compiles (without errors), but, when executed, will not finish the execution till the end, because an error appears during the execution.

Rules

  • It has to be full program, which is compile-able or interpret-able in such way, that it produces no syntax errors.
  • You can use any mechanics, which will do something, so that the interpreter of your program kills the program. This includes (but is not limited to): exceptions, overflows, SIGSEGVs. However, asking the interpreter to kill the program explicitly does not count (by calling exit()-like functions).
  • It may be compiler/OS dependent, as long as it's not using obvious bug in compiler/interpreter. So depending on Undefined behavior in C/C++ is valid, but using version 1.0.17b of language interpreter, which throws random_exception when run is not. If it depends on something, it's good to write so in the answer.
  • The program will take no input, but it may (or may not) produce any output to STDOUT, or STDERR.
  • This is , but it is not about finding the language with least amount of bytes, but to find a least bytes solution in all languages. So I will not accept any answer.

Catalogue

I hope Martin Büttner won't get mad at me for copy-pasting his catalogue.

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

/* Configuration */

var QUESTION_ID = 61390; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 43365; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "http://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    else console.log(body);
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    lang = jQuery('<a>'+lang+'</a>').text();
    
    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list">
  <h2>Shortest Solution by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$

closed as too broad by Downgoat, mbomb007, Alex A. Oct 22 '15 at 5:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Don't worry about it; that snippet was made to be copy-pasted. ;) \$\endgroup\$ – ETHproductions Oct 21 '15 at 18:48
  • 4
    \$\begingroup\$ Would of done much better as a popularity contest \$\endgroup\$ – Downgoat Oct 21 '15 at 19:33
  • 1
    \$\begingroup\$ I didn't downvote but tbh, the challenge is not very interesting. The solution with the least amount of bytes will not be very creative most of the times. \$\endgroup\$ – Fabian Schmengler Oct 21 '15 at 19:58
  • 3
    \$\begingroup\$ For me, the scope of the question is simply far too wide: "write a program that doesn't work". For interpreted languages, the problem is ill-defined (and will usually hinge on "a compiler would spot this, but my language is interpreted, so...") - an example is @fschmengler's answer, which is within the scope of the question (I'm not criticising!), but wouldn't work in a compiled language. For compiled languages, a mature compiler's goal is to prevent the trivial answers to this question (except for exhaustion issues, perhaps). There is no "wow!" factor from this question as it stands. \$\endgroup\$ – JArkinstall Oct 21 '15 at 20:03
  • 1
    \$\begingroup\$ I think this would be better as a Popularity Contest. It seems too trivial, since print 1/0 is too easy. \$\endgroup\$ – mbomb007 Oct 21 '15 at 22:03

15 Answers 15

10
\$\begingroup\$

C, 5 bytes

main;

On modern systems it will crash because main is not in an executable section. On older systems it will execute some junk and crash.

\$\endgroup\$
  • \$\begingroup\$ Never knew about this! \$\endgroup\$ – kirbyfan64sos Oct 21 '15 at 19:28
5
\$\begingroup\$

Brainfuck, 1 byte

[

There's no matching ] to jump to. Depending on how smart your compiler/interpreter is, it may give you a syntax error, but the original spec didn't allow for syntax errors - only runtime errors.

Try it online

\$\endgroup\$
4
\$\begingroup\$

Python, 1 byte

_

NameError! :D

This works because NameErrors in Python occur at run-time, NOT compile-time.

\$\endgroup\$
  • \$\begingroup\$ Heh, same as my JS answer ;) \$\endgroup\$ – ETHproductions Oct 21 '15 at 21:10
3
\$\begingroup\$

CJam, 1 bytes

;

This will try to pop from an empty stack.

Try it online.

\$\endgroup\$
2
\$\begingroup\$

JavaScript Shell, 7 bytes

clear()

The clear function has been quite controversial but to clarify this uses the SpiderMonkey shell. It will throw a Segmentation fault: 11

\$\endgroup\$
2
\$\begingroup\$

PHP, 7 Bytes

<?=o();

This Santa smiley crashes with Fatal error: Call to undefined function o() in [...]

\$\endgroup\$
  • \$\begingroup\$ <?=0/0; would have been shorter but I got tired of division by zero errors. \$\endgroup\$ – Fabian Schmengler Oct 21 '15 at 19:46
  • 1
    \$\begingroup\$ 0/0 will only raise a warning like Warning: Division by zero in Command line code on line 1. "will not finish the execution till the end" would not be satisfied. PS: congrats to 1k rep. :) \$\endgroup\$ – insertusernamehere Oct 21 '15 at 20:27
  • \$\begingroup\$ Ah, of course you are right \$\endgroup\$ – Fabian Schmengler Oct 21 '15 at 20:29
  • \$\begingroup\$ Try this: <?$a();. It will produce: Notice: Undefined variable: a in [...][...] on line 1\nFatal error: Function name must be a string in [...][...] on line 1 (The \n is a real newline). (Evidence: sandbox.onlinephpfunctions.com/code/…) \$\endgroup\$ – Ismael Miguel Oct 24 '15 at 13:53
1
\$\begingroup\$

C#, 36 bytes

class C{static void Main(){Main();}}

Throws a StackOverflowException. I can't remove the main function and still have it compile.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 1 byte

_

Tries to access the undefined variable _, which raises a ReferenceError. JS doesn't check for inexistent variables until runtime, so if you tried this code:

console.log("No error??/")
_
console.log("Huh...")

It would error out with ReferenceError: _ is not defined, then print No error??/, but not Huh....

\$\endgroup\$
0
\$\begingroup\$

T-SQL, 9 bytes

EXEC('@')

Causes the following error

Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@".
\$\endgroup\$
0
\$\begingroup\$

Pyth, 3 Bytes

/00

Result:

 Traceback (most recent call last):
  File "pyth.py", line 671, in <module>
  File "<string>", line 3, in <module>
  File "/app/macros.py", line 506, in div
ZeroDivisionError: integer division or modulo by zero
\$\endgroup\$
  • \$\begingroup\$ You can actually just use /, which will throw an ArgumentError at runtime. \$\endgroup\$ – kirbyfan64sos Oct 22 '15 at 14:14
0
\$\begingroup\$

PoGo, 2 Bytes

vi

Result

EXCEPTION_INT_DIVIDE_BY_ZERO
\$\endgroup\$
0
\$\begingroup\$

C++, 23 bytes

int main() {
    main();
}

Crashes with Segmentation fault: 11

\$\endgroup\$
  • 2
    \$\begingroup\$ This would be shorter if some of the whitespace were removed. \$\endgroup\$ – ETHproductions Oct 21 '15 at 21:18
0
\$\begingroup\$

Haskell, 10 bytes

main=[]!!0

Fails with the Prelude.!!: index too large error.

\$\endgroup\$
0
\$\begingroup\$

STATA, 1 byte

a

Outputs unrecognized command: a, but this error occurs at run-time.

For an error not in the range 100 to 199 (considered syntax errors), use

set ob `=9^9'

This gave me the following to standard error: op. sys. refuses to provide memory Stata ran out of room to track where observations are stored. Right now, Stata has 1m bytes allocated to track observations. Stata requested an extra 738m bytes (in 738 1m pieces) and the operating system said no. Stata is currently tracking 0 observations and was asked to track 0. You are up against the memory limits of this computer.

\$\endgroup\$
0
\$\begingroup\$

Loader, 8 bytes

There are shorter solutions, but this is the shortest one that's actually legal syntax:

throw ""

Throws the empty string as an error message (which, in the reference implementation, corresponds to a popup error notification reading Error: followed by a single trailing space).

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.