Catch errors thrown in the OnError handler.

#1836