Catch/Throw

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zerofury
    New Member
    • Jun 2007
    • 9

    Catch/Throw

    I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

    Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

    Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
    And can you make a subclass of a subclass?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Zerofury
    I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

    Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

    Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
    And can you make a subclass of a subclass?
    It has already been done for you:

    [code=java]
    public static void main(String[] args) {

    try {
    // your code here
    }
    catch (Throwable t) {
    // handle all possible exceptions here
    }
    [/code]

    ... but it's a very bad idea, i.e. your 'master handler' can't possibly know whatever
    went wrong deep down in your code. Better handle exceptions as close to
    where they are thrown.

    kind regards,

    Jos

    Comment

    • praveen2gupta
      New Member
      • May 2007
      • 200

      #3
      Originally posted by Zerofury
      I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

      Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

      Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
      And can you make a subclass of a subclass?
      hI

      Try and Catch block is used close to the exceptions. In a program there may be many try-catch blocks. There are some specific objects and classes which always ask for try-catch block. So it is not an good idea to handle all exceptions of the program at single location.you should use them separately.

      It is possible to make subclass of a subclass. In that situation earlier subclass will act as a super class for the latter one.

      Comment

      • odefta
        New Member
        • Jul 2007
        • 18

        #4
        You can make any subclass of subclass :)

        Comment

        Working...