Extend ExceptionHandler to allow user defined exceptions and exception tagging

Created by: wgurecky

This is a proposed enhancement of ExceptionHandler to allow the registration of user defined exception types derived from a base exception type.

Benefits

  • Usability: allow client code to handle an unlimited variety of exceptions without having to interrogate the log file or look at the lastMesg string.
  • Code organization: place logic regarding error message generation into the user exception type.

Proposed Design

Module ExceptionHandler

ExceptionHandlerType

Attributes

  • Remove: nError, nWarning, ect. verbose, quiet
  • New: exceptionRegistry - contains user defined exceptions.
  • New: isInit - bool flag

Methods

  • New method: init() - Fill the exceptionRegistry with the 5 default exception types.
  • New method: registerException(e,userExcept) - enforce unique tags
  • New method: raise(e,userExcept,msg) or raise(e,tag,msg)
  • New method: getErrorCountByType(e,userExcept) or getErrorCountByTag(e,tag)
  • Remove: logMessage
  • Remove: exceptionStop
  • Redef: raiseError, raiseWarning, ect become aliases to the more general raise method.
Notes:
  • Enforce that init() is called before using the exception handler.
  • Keep all existing functionality for legacy support. All existing ExceptionHandler tests should pass.
  • Unresolved: how to safely copy from surrogate and defer raises to surrogate.

Module ExceptionType

ExceptionTypeBase

Attributes

  • tag - integer, unique id of exception type
  • counter - integer
  • quiet - bool flag
  • verbose - bool flag
  • stopmode - bool flag

Methods

  • init(tag)
  • onRaise(isQuiet, isLogActive,logUnit,mesg)
  • getCount, setCount, getQuiet, setQuiet, getVerbose, setVerbose
  • logMessage(isQuiet, isLogActive,logUnit,mesg)

Virtual

  • genPrefix

Module (non Type-bound)

  • exceptionStop(stopmode)

ExceptionTypeError,extends(ExceptionTypeBase)

  • genPrefix() -> "#### EXCEPTION_ERROR ####"