3 ms·
What happens when a cast is invalid? You have type-safe casts in Haskell, for instance, where the failure is reflected at runtime. cast :: (Typeable a, Ty
by tel 12y ago
What happens when a cast is invalid?
You have type-safe casts in Haskell, for instance, where the failure is reflected at runtime.
cast :: (Typeable a, Typeable b) => a -> Maybe b
Those are alright.
- AnimalMuppet 12y agoIn Java, IIRC, the cast fails with a ClassCastException. That seems to me to be "failure is reflected at runtime". In C++ with RTTI, IIRC it returns null. That's also "failure at runtime" (of a sort), but you have to check it.
- jeorgun 12y agoRTTI returns nullptr when casting a pointer, but it does throw an exception when casting references. Both of these behaviors are well-defined, although the first is kind of questionable.