Solved

grouping of exceptions

Posted on 2004-10-19
7
222 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
MySQL  on Tomcat 8 68
hibernate example for saving data 19 52
running on tomcat not jboss eap 7.0 3 18
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

839 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