The #’on:do:’ implementation in Block accepts either an Exception or an ExceptionSet as the first parameter. So you can do something like the following (I’m typing from memory without trying so may have syntax errrors):
[ “tryBlock” ] on: (Array with: ExceptionOne with: ExceptionTwo) do: [:ex | (ex isKindOf: ExceptionOne) ifTrue: [ “handleOne” ]. (ex isKindOf: ExceptionTwo) ifTrue: [ “handleTwo” ]. ]. The above code can be improved in a variety of ways, but it should get you started. Note also that since Smalltalk allows you to modify base classes, you could add #’on:do:on:do:’ to Block. James > On May 25, 2023, at 8:24 AM, mlnt...@gmail.com wrote: > > In other languages there is the possibility to chain exception handlers like > this: > > try { doOne(); doTwo(); doThree(); } > > catch(ExceptionOne ex){ > > handleOne(); > > } > > catch(ExceptionTwo ex) { > > handleTwo(); > > } > > catch(ExceptionThree ex) { > > handleThree(); > > } > > catch(Exception ex) { > > handleRest(); > > } > > Is this possible in Pharo? I’ve tried > > [ block ] > > on: ExceptionOne do: [ handleOne ] > > on: ExceptionTwo do: [ handleTwo ] > > but it is invalid syntax. >