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 subclass: #GtMoldableExceptionSpecificDebuggerSpecification instanceVariableNames: 'debuggingViewPragmaNames availableAutomatically activationPredicate sessionClass icon title priority' classVariableNames: '' 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 subclass: #GtMoldableExceptionDebuggingElement instanceVariableNames: 'toolbar viewsContainer mainTab compositeView debuggingConfiguration' classVariableNames: '' 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.

Debugging Views

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
  

Target Objects

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 subclass: #GtMoldableExceptionDebuggingViewTargets instanceVariableNames: 'exceptionTarget objectTargets' classVariableNames: '' package: 'GToolkit-Debugger-MoldableExceptions' that contains all the individual debugging targets (GtMoldableExceptionDebuggingViewsObjectTarget Object subclass: #GtMoldableExceptionDebuggingViewsObjectTarget instanceVariableNames: 'targetObject' classVariableNames: '' 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 .

Enabling/disabling debugging extension

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.

Global Debugging Actions

Exceptions can add global debugging actions in the toolbar of the debugger. Global debugging actions are subclasses of DebugAction Object subclass: #DebugAction instanceVariableNames: 'label order icon keymap category debugger needsValidation needsUpdate needsSeparatorAfter actionSelector' classVariableNames: '' package: 'GToolkit-Debugger-Actions' .

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