In Delphi, if there was an exception during construction of an object: any allocated memory would be released and an exception would be thrown. For example, the following was guaranteed to either return a valid Camera
object, or throw an exception:
Camera c = new Camera();
You never had to check the resulting variable for null:
Camera c = new Camera();
if (c == null)
throw new Exception("Error constructing Camera") //waste of time
Is the same true in the CLR?
And are there other syntatical constucts where a return value is guaranteed to either be valid, or throw an exception?
- Creating structures (e.g. Rectangle)?
- getting a member of an enumeration?
- the result of Object.ToString()?
- mathmatical operations?
In the case of performing math:
Int32 aspect = 1650.0 / 1080.0;
if (aspect == null)
throw new Exception("Division of two numbers returned null")