Question

I don't see much of a difference between the concerns of exception handling and logging in that both are cross cutting concerns. What do you think? Shouldn't it be handled separately on its own rather than interleaved with the core logic a method is implementing?

EDIT: What I am trying to say, is that in my opinion a method implementation should only contain the logic for the successful path of execution and exceptions should be handled elsewhere. This is not about checked/unchecked exceptions.

For example, a language might handle exceptions in a fully checked way by using constructs like this:

class FileReader {

  public String readFile(String path) {
    // implement the reading logic, avoid exception handling
  }

}

handler FileReader {

   handle String readFile(String path) {
      when (IOException joe) {
        // somehow access the FileInputStram and close it
      }
   }

}

In the above conceptual language, the program won't compile in the absence of FileReader handler, because the FileReader class's readFile is not throwing the exception. So by declaring the FileReader handler, the compiler can ensure that it is being handled and the program then compiles.

This way we have the best of both of checked and unchecked exception problems: robustness and readability.

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top