Added a check and more info-rich exception on cast
Merge remote-tracking branch 'origin/pr/673'