The message loop can not be used for error handling. Hooking won't work either for error messages.

Errors in a software program fall in two categories - errors that can be solved by software, f.i. by aborting a function, and errors that are fatal and could cause a crash when the program continued. The former can be masked out, the latter can't. Your script must take precautions so that those errors don't happen.