Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

grouping of exceptions

Posted on 2004-10-19
7
Medium Priority
?
243 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
5 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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ā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

773 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