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>>#gtDebuggingExtensionConfiguration gtDebuggingExtensionConfiguration "Return a debugging configuration with default values." ^ GtMoldableExceptionDebugingExtensionConfiguration 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 GtMoldableExceptionDebugingExtensionConfiguration GtMoldableExceptionDebuggerConfiguration subclass: #GtMoldableExceptionDebugingExtensionConfiguration instanceVariableNames: 'debuggingViewPragmaNames globalDebuggingActionPragmaNames enableDebuggingViewExtensionComputation debuggingTargets' 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 GtMoldableExceptionDebugingExtensionConfiguration>>#debuggingViewPragmas: debuggingViewPragmas: aCollection "Configure the list of pragmas used to look for debugging views." debuggingViewPragmaNames := aCollection . By default the pragma gtExceptionDebuggingView is used.

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

#gtExceptionDebuggingView 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 GtMoldableExceptionDebugingExtensionConfiguration>>#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 GtMoldableExceptionDebugingExtensionConfiguration>>#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 GtMoldableExceptionDebugingExtensionConfiguration>>#enableDebuggingViewExtension: enableDebuggingViewExtension: aBlock "Configure the block used to determine is to enable the domain-specific debugger associated with this exception." enableDebuggingViewExtensionComputation := 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 GtMoldableExceptionDebugingExtensionConfiguration>>#globalDebuggingActionPragmas: globalDebuggingActionPragmas: aCollection "Configure the pragmas used to look for global debugging actions. These actions are specific to the exception." globalDebuggingActionPragmaNames := aCollection .