Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

grouping of exceptions

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

722 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