Catch exception during replacing words