Examples of moldable exceptions

This page shows several examples of Moldable Exceptions together with code snipepts for working with them.

GtExampleExceptionWithDebuggingView Exception subclass: #GtExampleExceptionWithDebuggingView instanceVariableNames: 'actualString expectedString' classVariableNames: '' package: 'GToolkit-Debugger-Examples' is an exception that defines a single debugging view using #selector gtViewDiffFor: aView <gtView> <gtExceptionView> ^ aView forward title: 'Diff'; priority: 1; object: [ self computeDiff ]; view: #gtTextView:; actionButtonIcon: BrGlamorousVectorIcons inspect tooltip: 'Inspect the comparator' action: [ :aButton | aButton phlow spawnObject: self computeDiff ] . It uses the default extensions without any configuration.

exception := GtExampleExceptionWithDebuggingView new
	expectedString: GtExampleComparisonExceptionWithDebuggingViews new
		expectedShortStringForTest;
	actualString: GtExampleComparisonExceptionWithDebuggingViews new
		computedShortStringForTest.
exception signal.
  

GtExampleComparisonExceptionWithDebuggingViews Error subclass: #GtExampleComparisonExceptionWithDebuggingViews instanceVariableNames: 'expectedString actualString targetSelector targetClass' classVariableNames: '' package: 'GToolkit-Debugger-Examples' is an exception that defines two debugging views.

exception := GtExampleComparisonExceptionWithDebuggingViews new
	expectedString: GtExampleComparisonExceptionWithDebuggingViews new
		expectedStringForTest;
	actualString: GtExampleComparisonExceptionWithDebuggingViews new
		computedStringForTest;
	targetClass: GtExampleComparisonExceptionWithDebuggingViews; 
	targetSelector: #expectedStringForTest.
exception signal.
  

Another way to get this exception is by using GtExampleExceptionComparisonTriggerExamples>>#testComputation testComputation <gtExample> <noTest> | computedData | computedData := self computeData. self assert: computedData equalsDataIn: #dataExpectedComputedOne. ^ computedData

GtExampleExceptionWithForwardedDebuggingView Exception subclass: #GtExampleExceptionWithForwardedDebuggingView instanceVariableNames: 'objectOne objectTwo objectThree' classVariableNames: '' package: 'GToolkit-Debugger-Examples' is an exception that has multiple debugging views defined in other domain objects. These objects where views are defined are speciffied by specializing the default configuration in #selector gtExceptionDebuggerSpecification "Create a debugging configuration that adds three extra domain objects where to look for debugging views, and that only enables the debugging extension if any of the three debugging objects has data." ^ super gtExceptionDebuggerSpecification addDebuggingTargetFor: self objectOne; addDebuggingTargetFor: self objectTwo; addDebuggingTargetFor: self objectThree; enableWhen: [ self objectOne hasData or: [ self objectTwo hasData or: [ self objectThree hasData ] ] ] .

exception := GtExampleExceptionWithForwardedDebuggingView new
	initializeWithDomainData.
exception signal.