How do I trap application error messages?

Due to the complicated process of aborting transfers using a FTP component,
my application generates a "500 'Abort': command not understood." messagebox
when aborting a transfer, with an Ok button.. How do I trap such a error
message so it doesn't appear?

Thanks in advance.