Wrap type checking in a try catch

Interesting bug coming from Firefox. Closes #265.