Catch errors when serializing values using #to_s and #inspect