Stopping MQExceptions being logged to the console in Java

I've been writing some Java code that uses the WebSphere MQ base Java API. When there is an error, even if the MQException is caught, I've been finding that the exception is logged to the console.

There's a simple way to stop this from happening. Somewhere in your initialization method, you can include this statement:

// by default, MQExceptions are logged on System.err
// this will switch off that behaviour
MQException.log = null;

Of course, you can – and should! – still catch and handle the exceptions as normal, and get at the text of the exception if required. This just prevents them from always being printed on the console (or location of System.err).

2 responses to “Stopping MQExceptions being logged to the console in Java

  1. Pretty awkward behaviour to have all the exceptions logged by default imho. Actually I don’t think libraries should log at all but rather provide some form of hook, or as Nat Pryce puts it “Tell, don’t log”:


  2. I’m inclined to agree with you, and I will feed this back to the development team.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s