• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chained Exceptions

 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use the Chained Exception class provided at JavaWorld
in the assignment. Without changing can the same class be used. Will I be penalized if I use that class as it is.
[ April 08, 2003: Message edited by: Saraswathy Krishnamoorth ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.4 offers chaining through normal exceptions, so you could use that. But no, you can't use third party classes.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Max.
 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have to use chained exception, userdefined Exception class has a memebr varialbe Throwable and it has to overlaod the following method
public FBNException(String message, Throwable cause) {
super(message);
this.cause=cause;
}
in addition to overloading public FBNException(String message) method. Also should have a method to retrieve the member variable.
Max, Is my understanding correct. Also how many levels of chaining can be achieved. For example,
Say Class A catches exception a1 and throws a new exception b1, then class B catches exception b1 and throws exception c1. Then class c catches c1. So is it possible to track exception b1 and a1 in c apart from exception c1. Please clarify.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand the first part of your question, but as for the second, I believe you can nest exceptions to any degree of depth required.
M
 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max my first question is
1) If I have to use chained exception,
MyOwnException class should have a member varialbe Throwable and it has to overload the following method public FBNException(String message, Throwable cause)
in addition to overloading public FBNException(String message) method. Also MyOwnException class should have a getmethod to retrieve the Throwable member variable.
Is this correct.
Thanks Max.
[ April 08, 2003: Message edited by: Saraswathy Krishnamoorth ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no. It's true that constructors are not inherited, so you would provide your own. However, in jdk 1.4, the Exception class has been retrofitted with some nifty new methods, like initCause(sp?), getCause(sp?), that should help you out.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Saraswathy Krishnamoorth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Max.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic