+13

Is Java the only language that has Checked Exceptions?

I'm not asking about the definition of checked and unchecked exceptions, so please don't post a link to such a source. I'm just asking if you know a language other than Java which checks for the handling of exceptions by the programmer at compile time.

3/25/2019 6:03:37 AM

Sonic

9 Answers

New Answer

+8

Schindlabua,Vigil deletes source code at run time? That's the first time I've heard of that!

+8

That's OK ⚡Prometheus ⚡ . And congratulations on halfway to level 18!

+7

https://www.sololearn.com/discuss/1208853/?ref=app Not for you Sonic, I had to put this here in case anyone seeing this question does not get what you mean.

+5

Sonic Yeah it's a joke language but I thought it was pretty funny. :D

+4

Sonic C++ used to have checked exceptions but the compiler implementors usually ignored it or enable it using compiler options. The reason was exception specification adds to the object model and makes it bulky, thus affects the performace/optimizations. The purpose of checked exception is to recover the system to a stable state before the exception occured. Due to chaning of exceptions it means the stack frame may needs to be unwind far too back in time and to do that you need a lot of internal book keeping. The memory/object and compilation model of the programming languages often make stack unwinding difficult. So now C++ allows methods to specify whether it will throw an exception or not. If you are throwing an exception deal with it else the program terminates void fun() nothrow <-- will not throw an exception void fun() nothrow(false) <-- can throw an exception Exception handling is not a trivial task in any programming language.

+3

Nice question! I'm not aware of any others. Checked Exceptions are pretty unpopular even among Java folk, so if there aren't any now, there probably won't be in the future. In C++ there is `noexcept` which does some compile time checks to make sure a function does not throw an exception, I guess that's similar but also opposite. And then theres languages without proper exceptions but that's also not really the same. Haskell typically communicates error with the `Either` and `Maybe` types which pass through the typechecker like everything else. (There is Control.Exception but I digress). And for fun I'll mention Vigil, which will delete your source code when it finds an unhandled exception, to punish you. All runtime though and not really checked at all. I guess you have a compile-time contract with the runtime to be vigilant.

+2

Yes, the concept of checked exceptions as such does only exist in Java.

+2

@Sonic: yes, Vigil is a very "safe" esoteric programming language that does try to not allow unhandled exceptions ;-) https://github.com/munificent/vigil

+1

In Python programming exception handling is like a fun and joyable 😀