'need to continue after the MQ exception MQRC_UNKNOWN_OBJECT_NAME in java( Sprinngboot)

I have following method to send a message to MQ , when the queue name is incorrect it throws MQRC_UNKNOWN_OBJECT_NAME error, but I want to pass the custom error (something like "queue name is not found") and let the user to continue with a correct queue name. I tried to capture the message send not successful scenario by returning the mqSend() method as false. but it doesn't work as I expected. Can someone help me out here? ( please note I'm setting the required MQ properties(QUEUE_NAME,QMGR,CHANNEL,HOST,PORT) separately.

    public boolean mqSend()
    {
        

        

    
        String APP_USER = ""; // User name that application uses to connect to MQ
        String APP_PASSWORD = ""; // Password that the application uses to connect to MQ

        
        // Variables
        JMSContext context = null;
        Destination destination = null;
        JMSProducer producer = null;
        //JMSConsumer consumer = null;
        
        
        try {
            // Create a connection factory
            JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
            JmsConnectionFactory cf = ff.createConnectionFactory();

            // Set the properties
            cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, HOST);
            cf.setIntProperty(WMQConstants.WMQ_PORT, PORT);
            cf.setStringProperty(WMQConstants.WMQ_CHANNEL, CHANNEL);
            cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
            cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, QMGR);
            cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, "Manual message publihser");
            cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
            cf.setStringProperty(WMQConstants.USERID, APP_USER);
            cf.setStringProperty(WMQConstants.PASSWORD, APP_PASSWORD);
            
            //cf.setStringProperty(WMQConstants.WMQ_SSL_CIPHER_SUITE, "*TLS12");

            // Create JMS objects
            context = cf.createContext();
            
            destination = context.createQueue("queue:///" + QUEUE_NAME);
            ((MQDestination)destination).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
            

            //long uniqueNumber = System.currentTimeMillis() % 1000;
            //TextMessage message = context.createTextMessage("Your lucky number today is " + uniqueNumber);
            TextMessage message = context.createTextMessage(MESSAGE);
            
            
            producer = context.createProducer();
            producer.send(destination, message);
            System.out.println("<INFO> : Sent message details:\n" + message);

            //consumer = context.createConsumer(destination); // autoclosable
            //String receivedMessage = consumer.receiveBody(String.class, 15000); // in ms or 15 seconds

            //System.out.println("\nReceived message:\n" + receivedMessage);

                        context.close();
return true;
            //recordSuccess();
        } catch (JMSException jmsex) {
            //recordFailure(jmsex);
            System.out.println("JMS/MQ error OCCURED!!!!");
return false;
        }
        

        //System.exit(status);
        
        
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source