Search Results

Search found 1 results on 1 pages for 'j unior'.

Page 1/1 | 1 

  • Central Exception Handler

    - by J-unior
    Recently I've been thinking about a general ExceptionHandler, that I could initialize once in my app context and inject it everywhere. The idea that it will have quite simple interface with just public void handle(Exception ex), and then according to exception type it should decide what to do, maybe just log it, or show an alert message to the user, or maybe kill the whole app. The question is, what is the prettiest way to write such handler without lots of instanceofs? Unfortunately googling gives me only the default exception handler for RuntimeException that was introduced in Java 5. My first idea is to create an enum, that will have Class field for exception type and it will return the appropriate execution point, for example a concrete exception handler that also implements the interface public void handle(Exception ex), but with the required casting already.

    Read the article

1