← Back to context

Comment by nofriend

9 hours ago

Types help the programmer. When the compiler gives me a type error, it is telling me about something I messed up and that would otherwise be an error at runtime. Sometimes the type system is wrong and I need an escape hatch. A type system that is wrong too often isn't very useful. For the majority of exceptions, there no useful thing that can be done at the call site to deal with them beyond bubbling them up the stack. A type system that constantly makes me explicitly deal with such errors is making my job harder, not easier.

There are plenty of errors/exceptions that don't need to be bubbled up the call stack. I don't think that's the main issue with them. Like you say the issue with checked exceptions is that there is no escape hatch to shut the compiler up and panic if you can't handle an error or its not possible. They desperately need a short hand like Rust's ?, Swift's try?, or Kotlin's !!.

    A a;
    try {
        a = someFnToGetA();
    } catch (AException aex) {
        // not possible in this situation
        throw new RuntimeException(aex);
    }

In a modern language that has checked errors that just becomes something like:

    val a = try! someFnToGetA();
    val a = someFnToGetA()!!