What I've learned about distributed services (part two)

Java is built in a way that developers are forced to always be doing exception handling. Period. It works by forcing the developer a) to surround any line of code that might throw an exception with a try/catch block. b) to declare ALL exception types involved in the throws clause (either not handled or thrown inside try/catch blocks). Thus, ALL methods in Java can be seen as a gateway of exception types: they receive incoming exception types (originating in the methods called inside), and output a mix of old and new exception types (that the caller will, in turn, handle). However, the compiler does NOT enforce these rules to runtime exceptions. This is the exception class hierarchy: Object └── Throwable ├── Error ← For serious problems (not meant to be caught) └── Exception ├── RuntimeException ← Base for unchecked (runtime) exceptions └── [Other Exceptions] ← Base for checked exceptions You can then wonder, what if I use a runtime exception for my application? This would free me from writing exception handling code, wouldn't it? As it turns out, this is (probably) your only option in the distributed realm.

May 20, 2025 - 21:40
 0
What I've learned about distributed services (part two)

Java is built in a way that developers are forced to always be doing exception handling. Period. It works by forcing the developer
a) to surround any line of code that might throw an exception with a try/catch block.
b) to declare ALL exception types involved in the throws clause (either not handled or thrown inside try/catch blocks).

Thus, ALL methods in Java can be seen as a gateway of exception types: they receive incoming exception types (originating in the methods called inside), and output a mix of old and new exception types (that the caller will, in turn, handle).

However, the compiler does NOT enforce these rules to runtime exceptions. This is the exception class hierarchy:

Object
 └── Throwable
      ├── Error               ← For serious problems (not meant to be caught)
      └── Exception
           ├── RuntimeException  ← Base for unchecked (runtime) exceptions
           └── [Other Exceptions] ← Base for checked exceptions

You can then wonder, what if I use a runtime exception for my application? This would free me from writing exception handling code, wouldn't it?

As it turns out, this is (probably) your only option in the distributed realm.