Refactor parseHandler

define basic error exceptions to handle exceptions
also add test case