Solved

grouping of exceptions

Posted on 2004-10-19
7
237 Views
Last Modified: 2010-03-31
Hi,

Does any one know how to group exceptions,

 for example grouping exceptions like IOException, Arrayindexboundexception, ArithemeticException into one name "XYZProjectException"

is it possible in java ? if so kindly add your coment here.

Thanks
Vijay
0
Comment
Question by:vijaysaravanan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12348875
Create your XYZProjectException, and then have all your other specific exceptions extend your overall exception

public class XYZProjectException extends Exception {}
public class SomeSpecificException extends XYZProjectException {}

If you mean to reverse engineer this into the existing exception hierarchy, sorry - but since there's already a hierarchy in place, use that instead?
0
 

Author Comment

by:vijaysaravanan
ID: 12348934
thanks for your reply

yes, i could able to understand ur reply and i need to group only three exception in that one instead of making a sub class to the exception.......

for example i have a third party library and i need to add that package exception name into the XYZProjectException  ??
0
 

Author Comment

by:vijaysaravanan
ID: 12348954
I think you have seen in many third party library where they may have their own exception name ...... and it is more clear that they have grouped many exception.

??
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12348983
what you might be able to do is add extra constructors to the XYZProjectException to construct it with these other exceptions:

public class XYZProjectException extends Exception {
    public XYZProjectException( ThirdPartyException e ) {
        this( e.getMessage() ); // or something like that that is useful to you!
    }
}

then when calling:

try {
   // something from 3rd party library
}
catch( ThirdPartyException e ) {
    throw new XYZProjectException( e );
}

hope this helps.
C.
0
 
LVL 11

Accepted Solution

by:
cjjclifford earned 100 total points
ID: 12349002
sorry, missed your second post at 9.20...

yes, basically, create your own exception, and try{}catch{} other exceptions, constructing your exception with details from the caught exceptions...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question