Results 1 to 2 of 2
  1. #1
    maxy04 is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Default java exception hierarchy

    Hello everybody. Excuse me for my english, i'm italian.

    I have a customized class for logging, that has a "log" method with overload, one for exception type (sqlexception, parseexception, and so on).
    every overloaded "log" method prints the detail of the exception: SQLException will print the sqlcode, parseexception prints another message, IncorrectConfigurationParameterException (my customized exception) will print the position of the error in the configuration file and so on.

    now my exception handling is like:



    try
    {
    ...............
    }

    catch (InterruptedException e)
    {
    log.log(WARNING, e, "");
    }
    catch (SQLException e)
    {
    log.log(WARNING, e, "");
    }
    catch (ClassNotFoundException e)
    {
    log.log(WARNING, e, "");
    }


    Every exception type i must define an exception handling.
    i would like to have



    try
    {
    ...............
    }

    catch (Exception e)
    {
    log.universalLog(WARNING, e, "");
    }


    and inside the method "universalLog" understand the "subclass" of the exception and handling it depending of the subclass.
    it is more clear and elegant, and i must not duplicate the code.
    but if i pass the exception as Exception, in the method i can't know the subtype (sqlexception, parseexception...).

    there is a way to do it?

    thanks for the help!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: java exception hierarchy

    Have you tried printing out the value of e to see if it has any useful data?
    Last edited by Norm; 11-03-2013 at 09:51 PM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. getting the hierarchy documented...
    By ajetrumpet in forum New To Java
    Replies: 2
    Last Post: 03-11-2013, 04:11 AM
  2. A question about hierarchy
    By Aggnavarius in forum New To Java
    Replies: 1
    Last Post: 09-05-2012, 05:38 PM
  3. Help with inheritance/hierarchy
    By klz215 in forum New To Java
    Replies: 2
    Last Post: 02-23-2012, 08:42 PM
  4. Hierarchy in Project
    By efozdel in forum New To Java
    Replies: 4
    Last Post: 07-23-2010, 09:49 AM
  5. Replies: 6
    Last Post: 07-04-2010, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •