| a b | b := MyBadParent new. "b doWork." b doSpecialWork. a := MyBadChild new. a doWork. a doSpecialWork. | s | s := 'fpp'. s error: 'I want a cookie'. ArithmeticValue divisionByZeroSignal handle: [ :ex | Transcript cr; show: ex errorString.] do: [ 4 // 0] | x y | x := 7. y := 0. [x / y] on: ZeroDivide do: [ :ex | Transcript show: 'zero divide detected'; cr ; show: ex errorString.]. | p | p := MyBadChild new. p doWithException. | x y | x := 5. y:=0. [x / y] on: ZeroDivide do: [:exception| "make the divisor very small but > 0" Transcript show: 'try again with non-zero!' ; cr. y := 0.00000001. exception retry] | p | p:=MyBadChild new. [p doTaskQuickly] on: MyException do: [:exception| exception retryUsing: [p doTaskEfficiently]] | f c d| c := OrderedCollection new. d := OrderedCollection new. c add:1 ; add: 2; add: $a ; add: 'abs' ; add: 9.8. d add: 5 ; add: 8 ; add: $z ; add: 'gte'. f := ReadStream on: c. f contents. f next. f next. f reset. f peek. f next. f upTo: 'abs'. f := WriteStream with: c. f nextPut: $f. f contents. f nextPutAll: d. f inspect. | file name contents| name := 'class.ws' asFilename. name exists. name fileSize. contents := name contentsOfEntireFile. Transcript show: contents ; cr. name := 'test.txt' asFilename. file := name writeStream. file nextPutAll: 'Here is some text for you!!!'. file close. | colorNames newColor bos | "First create a file containing color names." colorNames := ColorValue constantNames. bos := BinaryObjectStorage onNew: 'colors.b' asFilename writeStream. [bos nextPutAll: colorNames] ensure: [bos close]. "Then append a new color name." newColor := #mudBrown. bos := BinaryObjectStorage onOld: 'colors.b' asFilename readAppendStream. bos setToEnd. [bos nextPut: newColor] ensure: [bos close]. | xmlDoc parser | parser := XML.XMLParser new. parser validate: false. xmlDoc := parser parse: 'test.xml' asFilename. xmlDoc root inspect. | newDoc file writer node attr array| array := Array new: 1. newDoc := XML.Document new. attr := XML.Attribute name: 'name' value: 'Bob'. array at:1 put: attr. elements := OrderedCollection new. elements add: (XML.Element tag: 'name' attributes: nil elements: (OrderedCollection with: (XML.Text text: 'Hello world'))). elements add: (XML.Element tag: 'country' attributes: (Array with: (XML.Attribute name: 'continent' value:'Africa')) elements: (OrderedCollection with: (XML.Text text: 'Timbuktu'))). node := newDoc addNode: (XML.Element tag: 'employee' attributes: array elements: elements). file := 'out.xml' asFilename writeStream. file nextPutAll: ''; cr. writer := SAXWriter new output: file. [newDoc saxDo: writer] ensure: [file close]. | que sema delay | delay := Delay forSeconds:10. sema :=Semaphore new. que := SharedQueue new. [ sema wait. Transcript show: ' Done waiting on semaphore ' ; cr.] fork. [ delay wait. Transcript show: ' delay over, sending signal' ; cr. sema signal. que nextPut: $a.] fork. [Transcript show: 'getting next item from q ' ; show: que next ; cr.] fork.