fixed typo in error handling code; added tests for bad input

Previously, if input was bad, the error handling had an extra "new" inserted.  This commit fixes that, and adds tests to cover error handling.