[squeak-dev] Exception patterns (The Inbox: Kernel-ct.1292.mcz)

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Fri Jan 3 01:54:57 UTC 2020


Please note that the #on:when:do: proposal would be only one possible implementation. Another idea of mine was to expand ExceptionSets and implement the common exception protocol also on BlockClosure! Watch some rewritten examples based on a true image:


[self model merge]

on: MCMergeResolutionRequest & [:request |
request merger conflicts notEmpty]

do: [:request | request resume: true].


[client unusedBytecode]

on: MessageNotUnderstood

& [:ex | ex receiver == client]

& [:ex | ex message selector == #unusedBytecode]

do: [self error: 'unusedBytecode'].


references := [self resolvePackageSpecReferences: packageSpec gofer: gofer]
on: [self class retryPackageResolution] & (Error , GoferRepositoryError)
do: [:ex | retryCount < 2 ifTrue: [
ex return: #()]
on: [self class retryPackageResolution] & GoferRepositoryError.
Transcript showln: 'gofer repository error: '; show: ex description printString; show: '...ignoring'.
(repositoryError := ex) resume: #()].

(original version of the latter was:
references := [ self resolvePackageSpecReferences: packageSpec gofer: gofer ]
    on: Error , GoferRepositoryError
    do: [ :ex |
        self class retryPackageResolution
            ifFalse: [ ex pass ].
        retryCount >= 2
            ifTrue: [
                (ex isKindOf: GoferRepositoryError)
                    ifTrue: [
                        Transcript showln: 'gofer repository error: ' , ex description printString , '...ignoring'.
                        repositoryError := ex.
                        ex resume: #() ]
                    ifFalse: [ ex pass ] ].
        ex return: #() ].

)

Another advantage against #on:when:do: would be integrated support for SUnit:


sz := 1024*1024*1024*1024.

self

should: [Array new: sz]

raise: OutOfMemory, (Error & [:ex | ex messageText
includesSubstring: 'basicNew: with invalid argument'])

I am excited to hear your opinions about both proposals!

Best,
Christoph

________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Freitag, 3. Januar 2020 02:21 Uhr
An: squeak-dev at lists.squeakfoundation.org
Betreff: [squeak-dev] The Inbox: Kernel-ct.1292.mcz

A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1292.mcz

==================== Summary ====================

Name: Kernel-ct.1292
Author: ct
Time: 3 January 2020, 2:21:26.297116 am
UUID: 95936a10-85a4-734e-a10b-0f87290b70f9
Ancestors: Kernel-nice.1291

Proposal: Implement conditional exception handling on blocks. The nomenclature is inspired from usual practice in .NET languages.

For an impression of possible users, have a look at:

        self systemNavigation
                browseMessageList: ((self systemNavigation allCallsOn: #on:do: and: #pass) intersection: (#(ifTrue: ifFalse: ifTrue:ifFalse: ifFalse:ifTrue:) gather: [:sel | self systemNavigation allCallsOn: sel]))
                name: 'Potential users of #on:when:do:'

=============== Diff against Kernel-nice.1291 ===============

Item was added:
+ ----- Method: BlockClosure>>on:when:do: (in category 'exceptions') -----
+ on: exceptionOrExceptionSet when: aPredicate do: handlerAction
+
+        ^ self
+                on: exceptionOrExceptionSet
+                do: [:exception |
+                        (aPredicate value: exception)
+                                ifTrue: [handlerAction cull: exception]
+                                ifFalse: [exception pass]]!

Item was added:
+ ----- Method: BlockClosure>>on:when:ensure: (in category 'exceptions') -----
+ on: exceptionOrExceptionSet when: aPredicate ensure: aBlock
+
+        ^ self
+                on: exceptionOrExceptionSet
+                do: [:exception |
+                        (aPredicate value: exception)
+                                ifTrue: [aBlock value].
+                        exception pass]!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200103/8f418170/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: exception patterns.2.cs
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200103/8f418170/attachment-0001.ksh>


More information about the Squeak-dev mailing list