Throw an exception when object is invalid

Fix #41
Added tests on invalid object exception
Merge branch 'fix/object'