Exception handling refactor to include error code. (Code changes on behalf of Ulka)

Exception handling refactor to include error code. (Code changes on behalf of Ulka)