Why is catching checked exceptions allowed for code that does not throw exceptions?

Quoting the Java Language Specification, ยง11.2.3: It is a compile-time error if a catch clause can catch checked exception class E1 and it is not the case that the try block corresponding to the catch clause can throw a checked exception class that is a subclass or superclass of E1, unless E1 is Exception or … Read more

Difference between Unchecked exception or runtime exception

As stated by their name, unchecked exceptions are not checked at compile-time which means that the compiler doesn’t require methods to catch or to specify (with a throws) them. Classes belonging to this category are detailed in the section 11.2 Compile-Time Checking of Exceptions of the JLS: The unchecked exceptions classes are the class RuntimeException … Read more

Understanding checked vs unchecked exceptions in Java

Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. They were eliminated in C# for example, and most languages don’t have them. So you can always throw a subclass of RuntimeException (unchecked exception) However, I think checked exceptions are useful – they are … Read more

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