Link to home
Start Free TrialLog in
Avatar of dpalyca755
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?
Avatar of Am P
Am P
Flag of India image

Avatar of dpalyca755
dpalyca755

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?
---------------------------------------------------------------------
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 
       }
} 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial