[rabbitmq-discuss] it throws AlreadyClosedException, not IOException.

张博强 boqiang.zhang at gmail.com
Thu Apr 28 08:57:57 BST 2011

I'm using rabbitmq java client 2.4.1

After a TCP connection lost, and still call a method on a channel over
this connection, a AlreadyClosedException will be thrown.

it is a bug? I expected an IOException,  but AlreadyClosedException I
got, and AlreadyClosedException is a RuntimeException.

if not, why all other errors cause an IOException.

      public void testConnectionLost() throws IOException{
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("<your rabbitmq host>");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();
		try {
			channel.queueDeclare("queueName", false, false, false, null);
			Assert.fail("Exception expected.");
		}catch (IOException e) {
                 	//it will NOT reach here.
			//Inner exception should be AlreadyClosedException
		}catch (AlreadyClosedException e) {
			// it will reach here.

			//this is strange!
			//I expected IOException , but AlreadyClosedException I got.
			//And AlreadyClosedException is a RuntimeException.

Thank you.

More information about the rabbitmq-discuss mailing list