Questions tagged [error-handling]

Use this tag for questions about handling errors in a programming language at compile-time or how to manage them at runtime. Do not use this tag for general programming error handling questions.

Filter by
Sorted by
Tagged with
12 votes
2 answers
543 views

How to tolerate syntax errors in a typed language?

In my tokenizers and parsers, once I find a syntax error (like an unexpected token) I usually throw a fatal exception that finishes parsing of the input source. The downside of how I usually do it is ...
Hydroper's user avatar
  • 909
14 votes
12 answers
7k views

Can sine converge to zero at infinity?

In common languages, sine produces an error, NaN, or exception when evaluated at infinity. For example, in Python: ...
Corbin's user avatar
  • 724
4 votes
4 answers
398 views

What goes wrong when division-by-zero is defined as multiplication-by-infinity?

Sometimes, we want to implement floating-point operations on systems which use IEEE 754 representations of values, but don't necessarily support IEEE 754 semantics. For example, we may be using the <...
Corbin's user avatar
  • 724
5 votes
1 answer
172 views

What sort of "syntax error recovery" is possible for this indentation based language?

I am thinking of how to write the parser/compiler so it works as a VSCode Language Server Extension, so I can have it show syntax errors, do autocomplete, and other things, in VSCode. One thing that I'...
Lance's user avatar
  • 695
12 votes
4 answers
2k views

Why would a language have different error handling for libraries and applications?

Rust has two popular packages for augmenting its error handling: anyhow, for libraries, created by David Tolnay. thiserror, for applications, created by David Tolnay. They control how errors are ...
BoppreH's user avatar
  • 1,441
3 votes
1 answer
154 views

What are the pros and cons of showing multiple parse errors at once?

The alternative to showing multiple parse errors at once is to display and handle each error individually as they are encountered during the parsing process, which I would presume is simpler to ...
Starship - On Strike's user avatar
8 votes
1 answer
198 views

In a language with explicit error handling, how to reduce boilerplate for common fallible operations?

Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail. This works well for I/O and complex algorithms, but how should common ...
BoppreH's user avatar
  • 1,441
18 votes
5 answers
2k views

What should be included in error messages?

New users of a language will spend a lot of their time staring at error messages, and realistically so will the language designers. These messages should be an early consideration, given that adding ...
BoppreH's user avatar
  • 1,441
21 votes
6 answers
2k views

How does one transpile valid code that corresponds to undefined behavior in the target language?

Consider the following C# snippet: Object bad= null; Console.WriteLine(bad.ToString()); This is valid C#. It will raise a ...
Robert Columbia's user avatar
4 votes
1 answer
128 views

Languages that compile to Lua bytecode (.luac) for including source locations?

The most popular language that transpiles to Lua is MoonScript. One problem with the MoonScript's compiler is that when a runtime error occurs on e.g. a table access the diagnostic source location is ...
Hydroper's user avatar
  • 909
13 votes
8 answers
536 views

Pros and cons of throwing an error versus returning a NaN value

So I've seen that many languages return a NaN value when calculating an indeterminate arithmetic expression (e.g. 0/0). Other ...
The Empty String Photographer's user avatar
13 votes
2 answers
169 views

What ways are there to determine if cascading compile errors are dependent or independent?

In my experience as a developer, a single syntax error made in a long program can result in a long cascading list of error messages, only the first of which is directly relevant to the solution. For ...
Robert Columbia's user avatar
17 votes
5 answers
859 views

Are very explanatory compiler error messages worth the effort needed to implement them?

This question is related to, but not the same as, What are some ways of reporting compilation errors? as that questions gets into the design of handling compiler errors at the compiler level (and the ...
Spevacus's user avatar
  • 615
31 votes
8 answers
3k views

Why would a language have a concept of undefined behavior instead of raising an error?

Certain constructs or conditions in programming just are not allowed. Languages such as Java or Swift handle these by raising an error when encountered. C and C++ on the other hand say 'Anything could ...
user16217248's user avatar
  • 7,535
7 votes
1 answer
254 views

How to report multiple compilation errors?

What are some good ways to report errors when compiling code in a new programming language? One answer may be to just stop after the first error, but this can be unsatisfactory because it takes ...
Isaiah's user avatar
  • 759
41 votes
13 answers
1k views

What are different ways of handling runtime errors?

Most languages have a system where exceptions are classes and you can throw them then use a try/catch block to handle them. What ...
mousetail's user avatar
  • 8,111