Improve exception handling when registering patterns.