Hacker News new | ask | show | jobs
by vbezhenar 2823 days ago
There are no checked exceptions in C++. throws in C++ is very different from Java, even if syntax is similar.
2 comments

You could declare throw() exceptions in C++. If you did that the runtime would intercept and typecheck any thrown exception against that list. Calling code could rely on that list since any not listed exception would cause the application to terminate. Modern C++ replaced that with noexcept - a function either can throw or it can't and template code can branch on that information.
Yes there are.

Just that instead of being a compiler error like in Java, the unexpected() handler is called; which by default calls terminate() to kill the application.

This behaviour has been removed in C++17.

However C++23 might introduce a similar syntax for value type exceptions, but following up semantics similar to how Swift does it.