Solved

grouping of exceptions

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now