dpalyca755
asked on
best practices for custom Exceptions
Is it good/normal practice to call another class to do something from inside a customException?
I want to clearly identify to an executive thread when something goes wrong in a weblogic producer class. I was thinking about uniquely catching all the various JMS exceptions, but want to throw one unique exception identifying that the weblogic interface has encountered a problem. I was thinking about defining and throwing a custom exception, and inside that class notifying the executive/main class to do some things? Is this the correct methodology?
I want to clearly identify to an executive thread when something goes wrong in a weblogic producer class. I was thinking about uniquely catching all the various JMS exceptions, but want to throw one unique exception identifying that the weblogic interface has encountered a problem. I was thinking about defining and throwing a custom exception, and inside that class notifying the executive/main class to do some things? Is this the correct methodology?
ASKER
For better context of my question:
I want to create a JMS Producer class which will continually attempt to connect if it can't connect on instantiation of the object itself or if onException is called denoting a connection failure.
Is the generic example I sketched out below the correct paradigm to do so?
-------------------------- ---------- ---------- ---------- ---------- ---
I want to create a JMS Producer class which will continually attempt to connect if it can't connect on instantiation of the object itself or if onException is called denoting a connection failure.
Is the generic example I sketched out below the correct paradigm to do so?
--------------------------
public class MyProducer implements ExceptionListener {
public MyProducer() {
super();
createConnection();
}
private void createConnection() {
try {
try {
// set up connection
// status as successful.
} catch (NamingException ne) {
ne.printStackTrace(System.err);
throw CustomException;
} catch (JMSException jmse) {
jmse.printStackTrace(System.err);
throw CustomException;
}
catch CustomException (e) {
createConnection();
}
}
public void onException(javax.jms.JMSException jsme) {
jsme.printStackTrace();
}
createConnection();
}
public synchronized void publishMessage(String Text) {
// build and send message
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.wikijava.org/wiki/10_best_practices_with_Exceptions
http://onjava.com/pub/a/onjava/2003/11/19/exceptions.html?page=1