You're right. The exception should be specific.
Also, there's a bug in this code. This gsub may work in an unexpected way.