Configuring moldable exceptions

This page describes the Moldable Exceptions mechanism for configuring a domain-specific debugger based on exceptions.

Exception define domain-specific debuggers through dedicated configurations. Each exception inherits a default configuration from Exception>>#gtExceptionDebuggerSpecification gtExceptionDebuggerSpecification <gtDebuggerSpecification> "Return a debugger specification with default values." ^ GtMoldableExceptionSpecificDebuggerSpecification forException: self that they can override and configure.

Use the snippet below to view all implementation of this method

#gtDebuggingExtensionConfiguration gtImplementors
  

Extensions configurations are instances of GtMoldableExceptionSpecificDebuggerSpecification GtMoldableExceptionDebuggerSpecification << #GtMoldableExceptionSpecificDebuggerSpecification slots: { #debuggingViewPragmaNames . #availableAutomatically . #activationPredicate . #sessionClass . #icon . #title . #priority }; package: 'GToolkit-Debugger-MoldableExceptions' . At run-time when an exception is not handled the configuration is used to instantiate a debugger of type GtMoldableExceptionDebuggingElement GtDebuggerElement << #GtMoldableExceptionDebuggingElement slots: { #toolbar . #viewsContainer . #mainTab . #compositeView . #debuggerSpecification }; package: 'GToolkit-Debugger-MoldableExceptions' that shows views and actions based on that configuration.

Next we look at various aspects that can be configured by an exception.

Exceptions can define one or more views shown in the debugger. Configurations can indicate the pragma with which these methods are annotate thorugh GtMoldableExceptionSpecificDebuggerSpecification>>#debuggingViewPragmas: debuggingViewPragmas: aCollection "Configure the list of pragmas used to look for debugging views." debuggingViewPragmaNames := aCollection . By default the pragma gtExceptionView is used.

Use the snippet below to see all debugging views in the system

#gtExceptionView gtPragmas
  

By default the debugger looks for debugging views in the exception object. However, users can add more objects where the debugger will look for debugging views. Like this debugging views can be added to any object.

The debugging configuration has a composite target, instance of GtMoldableExceptionDebuggingViewTargets Object << #GtMoldableExceptionDebuggingViewTargets slots: { #exceptionTarget . #objectTargets }; package: 'GToolkit-Debugger-MoldableExceptions' that contains all the individual debugging targets (GtMoldableExceptionDebuggingViewsObjectTarget Object << #GtMoldableExceptionDebuggingViewsObjectTarget slots: { #targetObject }; package: 'GToolkit-Debugger-MoldableExceptions' ) where the debugger looks for views.

The method GtMoldableExceptionDebuggerSpecification>>#addDebuggingTargetFor: addDebuggingTargetFor: anObject "Add a debugging target used to look for debugging views. It is possible to register multiple target objects, apart from the exception object." debuggingTargets addDebuggingTargetFor: anObject provides the entry point for adding a new target for a given object.

By default, the exception is a target for looking for views. We can remove it using GtMoldableExceptionDebuggerSpecification>>#withoutDebuggingExceptionTarget withoutDebuggingExceptionTarget "Indicate that the current exception should not be used for looking for debugging views" debuggingTargets withoutDebuggingExceptionTarget .

Even if an exception defines a debugging extension, depending on the state of the exception we might not want to show the domain-specific debugger for that exception.

We can control when the debugging extension is active by using GtMoldableExceptionSpecificDebuggerSpecification>>#enableWhen: enableWhen: aBlock "Configure the block used to determine is to enable the domain-specific debugger associated with this exception." activationPredicate := aBlock . This takes as a parameter a block, and the extension is enabled when the block returns true.

Exceptions can add global debugging actions in the toolbar of the debugger. Global debugging actions are subclasses of DebugAction Object << #DebugAction slots: { #label . #order . #icon . #keymap . #category . #debugger . #needsValidation . #needsUpdate . #needsSeparatorAfter . #actionSelector }; tag: 'Actions'; package: 'GToolkit-Debugger' .

An exception can indicate the pragma with which these classes are annotated using GtMoldableExceptionDebuggerSpecification>>#globalDebuggingActionPragmas: globalDebuggingActionPragmas: aCollectionOfSymbol "Configure pragma names used to look for global debugging actions. These actions are specific to the exception and are subclasses of DebugAction." globalDebuggingActionPragmaNames := aCollectionOfSymbol .