News for hackers. Stuff that matters.
Re:The road to Dart 3: A fully sound, null safe language by nradov on Thursday December 08, 2022 @11:43AM (#33909975)
Are there any popular languages which don't have unchecked exceptions? Java, for example, supports both checked and unchecked exceptions. In practice, checked exceptions seem to cause more problems than they solve for large scale software development. If you want to inherit from a class or interface it becomes impossible to add new checked exceptions to method signatures. So developers have to resort to hacks like wrapping the new checked exception in an unchecked exception.
Re:The road to Dart 3: A fully sound, null safe language by kaba0 on Thursday December 08, 2022 @12:23PM (#33910504)
This is a pet peeve of mine, checked exceptions map one-to-one to Result types, and in my opinion the former is strictly better (it automatically unwraps the ok result on successful execution, while makes the error handling as tightly scoped as one wishes (try block, leaving it out and auto-bubbling up) with native language support. Plus it includes proper stack traces which are a must in production systems (as much as some people hate them).

Now don’t get me wrong, Java’s implementation leaves much to be desired, inheritance is not the correct choice for denoting it, but I feel we really didn’t give it a proper choice.

Re:The road to Dart 3: A fully sound, null safe language by bbkane on Thursday December 08, 2022 @11:55AM (#33910140)
Neither Rust nor Go have exceptions at all, and I would consider them "popular" at thos point. To be fair, they each also make you think more about your error handling (there are multiple valid approaches in each language).
Re:The road to Dart 3: A fully sound, null safe language by pianoben on Thursday December 08, 2022 @01:00PM (#33910934)
Go and Rust each do have exceptions - in both languages they are called "panics". Both can (usually) be intercepted and recovered.
Re:The road to Dart 3: A fully sound, null safe language by kaba0 on Thursday December 08, 2022 @12:24PM (#33910523)
Go’s error handling is as good as C’s. And that is not a praise.
Re:The road to Dart 3: A fully sound, null safe language by dysarray on Thursday December 08, 2022 @11:58AM (#33910169)
Rust does have a feature called "panics" that is similar to exceptions in other languages. A panic in Rust is an unrecoverable error that can occur at runtime. Unlike exceptions, however, panics are not caught automatically by the language runtime. Instead, panics are propagated up the call stack until they reach a "catch point", where they can be handled by the programmer.
Re:The road to Dart 3: A fully sound, null safe language by masklinn on Thursday December 08, 2022 @12:09PM (#33910321)
1. An exception is a recoverable error, that's the entire point, that's what catching an exception is.

2. Unlike Go's, rust's panics do not actually, universally, get "propagated up the call stack until they reach a "catch point", where they can be handled by the programmer". There's a compiler flag which can be "unwind" or "abort". In the former case (the default), panics can be caught and recovered from. In the latter case, the program gets hard-stopped on the spot.

Re:The road to Dart 3: A fully sound, null safe language by cwzwarich on Thursday December 08, 2022 @12:25PM (#33910525)
> Unlike Go's, rust's panics do not actually, universally, get "propagated up the call stack until they reach a "catch point", where they can be handled by the programmer". There's a compiler flag which can be "unwind" or "abort". In the former case (the default), panics can be caught and recovered from. In the latter case, the program gets hard-stopped on the spot.

There are Rust libraries (e.g. salsa, used in rust-analyzer itself) that use unwinding internally for non-local control flow and won't work with unwinding disabled.

Re:The road to Dart 3: A fully sound, null safe language by dysarray on Thursday December 08, 2022 @12:16PM (#33910406)
2. In default Rust config, unhandled panics end up unwinding the stack, calling destructors for everything, freeing resources, closing files and sockets, and printing an error message and possibly a stack trace. I think this qualifies as the language runtime automatically catching the exceptions.

3. For 99% of users, panic = unwind in rust. If you play with compiler flags, C doesn't have undefined behaviour because ubsan will abort programs if you compile with the right flags.