How to catch packets erros

When sending packets, like registration packet, using the connection.sendpacket, Is there some global way to get an error if the action failed?

I run into failure in the registration, I had some error in my code and I did not pass the parameters right. I added a packet listener that will listen on regitration packets for errors, but, I’'m sending other packets as well.

Is there a global way to catch the error, or should I listen on aevery packet?

Thanks

(not tested, but should work)

Add a PacketListener to XMPPConnection, using a custom PacketFilter which accepts packets where packet.getError() != null