The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Exception-Handling Antipatterns
Subject:  New to Java
Date:  2007-11-25 14:42:35
From:  vanlimburga


I am very new to Java and found the article really useful - I have one (naive?) question -
In other discussion threads there was alot of issue with only producing the stack dump once - would an approach to this be (apologize in advance for any bad coding practice or where code is commented out - still working these bits out):
public class JadeSessionException extends RuntimeException {
static final long serialVersionUID = 76523;
private boolean logged = false;
public void logDetails (){
// prevent multiple stack dumps from being generated
Throwable lException = this;
while (lException!=null){
// Is the execption "one of ours"
if (!lException.getClass().getName().substring(4).contentEquals("Jade")) break;
// need to check value of "logged" - if true then set this to true also - then break
// TypeCast exception to be "one of ours" - check the "logged" flag
// if ("on of ours".logged) {
// logged = true;
// return;
// }
//
lException = lException.getCause();
}

if (!logged){
java.lang.System.out.println(getMessage() + "; " + toString() + "; " + getCause());
printStackTrace();
};
logged = true;
}

}

 Feed java.net RSS Feeds