- Topic
-
throws
- Method tells that it throws following exceptions
- Method can throw multiple exceptions
-
Or a Superclass of those multiple excpeption
- We should write separate catch blocks for multiple exceptions for clarity in debugging
-
Multiple catch blocks must be ordered from small to big
-
If you place big up then first one can catch it , and code in below catch blocks would be unreachable
- You would get Unreachable code compilation error
-
throw
- Method throw exception
-
try / catch
- When you call a method that throws some exception , you write your code in try / catch
-
try / catch / finally
- Finally code is always run
- If we have return statement in try , then immediately before return finally will run and then return
- Compile checks for all except Runtime exceptions
-
RuntimeExceptions
- They are mostly logic errors that must not be checked by compler
- Either handle using try/catch or duck it by throws
- Rules