Change an assertion to a proper error check fixing issue #166 as reported by Jan Blechta
Merge branch 'johanhake/fix-issue-166'