we should probably catch cast exception to produce better error messages