"
!classDefinition: #ExceptionExample category: #'ExceptionHandling-examples'!
Object subclass: #ExceptionExample
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ExceptionHandling-examples'!
"
Object newSubclassName: #ExceptionExample iVars: nil cVars: nil.

ExceptionExample ~> workingStuff
[
	| innerClosure |
	innerClosure := [:ex | ex return: #thwartedBadly].
	^self breakStuffWithInnerClosure: innerClosure
].


ExceptionExample ~> breakStuffWithInnerClosure: innerClosure
[
	| answer |
	answer := self protectedStuffToBreakWithInnerClosure: innerClosure.
	answer = #outer ifTrue: [^#workedWrong].
	answer = #thwartedBadly ifTrue: [^#thwartedProperly].
	^answer
].

ExceptionExample ~> breakingStuff
[
	| innerClosure |
	innerClosure := [:ex | ^#thwartedBadly].
	^self breakStuffWithInnerClosure: innerClosure
].

ExceptionExample ~> protectedStuffToBreakWithInnerClosure: innerClosure
[
	^[3 / 0.  #didNotFailAsItShould]
		on: ZeroDivide
		do: [:ex | innerClosure value: ex.  ex return: #outer]
].

"--- E O F ---"
