Creating / chaining exceptions and inheriting from their superclasses

M

Mark

I have written some exception classes below::

-----------------------
public class MemberException extends Exception {

private String memberID; // required for all MemberException
subclasses

public MemberException(String memberID, Throwable cause) {
super(cause);
this.memberID = memberID;
}
public String getMemberID() {
return memberID;
}
}
----------------------------
public class MemberRegistrationException extends MemberException {

// no extra data required yet in this exception so just call superclass
constructor
public MemberRegistrationException( String memberID, Throwable cause ) {
super(memberID, cause);
}
}
----------------------------
public class MemberRegistrationSQLException extends
MemberRegistrationException {

// this type of exception should have access to SQLException data and
inherited superclass data
SQLException cause;
int errorCode;
String SQLState;

public MemberRegistrationSQLException( String memberID, SQLException
cause ) {
super(memberID, cause);
}
public int getErrorCode() {
errorCode = cause.getErrorCode();
return errorCode;
}
public String getSQLState() {
SQLState = cause.getSQLState();
return SQLState;
}
------------------------------------------------------

The idea being that my data access object should throw a
MemberRegistrationSQLException up from my data access layer to the
controller layer of my Struts-based web application which I want to be able
to access all the methods and data of the MemberRegistrationSQLException
subclass and its superclasses i.e. MemberRegistrationSQLException,
MemberRegistrationException, MemberException (if/when defined) and so on up
the inheritance chain. JBuilder's MemberInsight is only showing the methods
available in MemberRegistrationSQLException but not the superclasses so
this would indicate to me that they are not being inherited.

I want to be able to do the following:

try {
int registerMemberResult = registrar.registerMember( member );
}
catch ( MemberRegistrationSQLException mrsqle ) {
servlet.log( "An error occurred while registering:
"+member.getMemberID(), mrsqle.getCause() );
}

but getCause() does not appear to be available, nor any other methods,
but should they not be inherited from the superclasses via inheritance?

I'm just learning about exceptions, chaining exceptions etc. so I may be
confusing the concepts slightly.

Thanks
Mark
 
A

Arvind

Mark,

Your theory is logical and perse there does not seem to be anything
wrong in what you expect to see....

May be there are some settings in JBuilder that needs tweaking ?

Arvind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top