Fixed Issue #1979

Fix for issue #1979.

Improved the error message and added a test case.
Please review the changes.