Catch exceptions while converting to JSON