Error checking before type-cast