Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have a ton of opinions on exceptions too, mostly because I love them.

FWIW you can override the stack trace collecting behaviour of Java exceptions. Not collecting the stack trace makes exceptions really fast and thats actually how Scala is implementing their boundary/break feature. I do kind of wish that Java could backtrack and that the stack trace would only be filled in on RuntimeExceptions that are true panics.

I really feel like Java just needs investment on the language syntax to make checked exceptions good. Things like `try!` or `try?` from Swift would be nice and taking Scala's try { as an expression with case catch blocks would make it really fluent. I think most devs can agree that they want to know what errors can happen, but currently in Java its just a pain to deal with them. Brian Goetz originally had some ideas around evolving the switch construct for this [0] so at least we know making exceptions better is on his radar.

[0] https://openjdk.org/jeps/8323658



> FWIW you can override the stack trace collecting behaviour of Java exceptions.

Could I ask you to point to an example?


    class MyException extends Exception {
        @Override
        public Throwable fillInStackTrace() {
            return this;
        }
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: