Fixed order of error exception arguments, and optionality of error handler arguments.
Replacement for #3940
Merge pull request #3802 from ezzatron/error-exception-arguments

Fixed 2 bugs in the error handler implementation
Fix conflicts and merge.