Exception process: focus on Application Server or on Databse?


EJB programming & troubleshooting: Exception process: focus on Application Server or on Databse?

  1. A large, complex system have N-tiers. How to handle the exceptions, such as the connection from Application Server
    to database is broken or session is lost, is a big issue for designer and architect to consider. How should we
    process, depend on the application server, or depend on the database to handle it? Please share your experience.

  2. Tiger,

    You'll get different answers to this question. A lot depends upon personal experience. But its a good question.

    For me, I prefer to extend Exception and create my own Exception class. With a custom-built exception class, you are able to define your own error-messaging charateristics. As you do QA testing, it also helps you to define areas in your application that need to have additional exception handling. In my opinion, no part of your application should ever throw _native_ Java exceptions.

    With the custom exception class, you should also have a class which defines 'user-friendly', context-sensitive error messages. These messages, you can display back to the user.

    For debugging purposes, in a log file (I highly recommend log4j) you should store the full stack trace of the internal exception.

    That's about all I can think of!

    Good luck!

    -- Rick

  3. Hi Rick,

    Thanks. Then you mean that you mainly depends on the application server' handling exception ability, and don't consider on the database area?
  4. Tiger,

    You should also handle all database exceptions and rewrap them with your own custom exception, as well.

    catch (SQLException sqle)
       throw new MyException(sqle);

    Or something to that nature.