Improve error handling for InstanceDouble and ClassDouble.