Surprising behavior of Java 8 CompletableFuture exceptionally method

This behavior is specified in the class documentation of CompletionStage (fourth bullet): Method handle additionally allows the stage to compute a replacement result that may enable further processing by other dependent stages. In all other cases, if a stage’s computation terminates abruptly with an (unchecked) exception or error, then all dependent stages requiring its completion … Read more

Why are Exceptions said to be so bad for Input Validation?

Reading these answers, I find it very unhelpful to say, “Exceptions should only be used for exceptional conditions”. This begs the whole question of what is an “exceptional condition”. This is a subjective term, the best definition of which is “any condition that your normal logic flow doesn’t deal with”. In other words, an exceptional … Read more

How can I throw an exception in Clojure?

You need to wrap your string in a Throwable: (throw (Throwable. “Some text”)) or (throw (Exception. “Some text”)) You can set up a try/catch/finally block as well: (defn myDivision [x y] (try (/ x y) (catch ArithmeticException e (println “Exception message: ” (.getMessage e))) (finally (println “Done.”)))) REPL session: user=> (myDivision 4 2) Done. 2 … Read more

Panic recover in Go v.s. try catch in other languages

Panic/Recover are function scoped. It’s like saying that you’re only allowed one try/catch block in each function and the try has to cover the whole function. This makes it really annoying to use Panic/Recover in the same way that java/python/c# etc. use exceptions. This is intentional. This also encourages people to use Panic/Recover in the … Read more

Why is it better to throw an exception rather than return an error code?

I’ve written about this at length: Exceptions vs. status returns, but briefly: Exceptions leaves your code clean of all the checks necessary when testing status returns on every call, Exceptions let you use the return value of functions for actual values, Exceptions can carry more information than a status return can, Most importantly: exceptions can’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)