June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,4 +1,3 @@
{{omit from|C}}
{{omit from|GUISS}}
{{omit from|M4}}
{{omit from|Retro}}

View file

@ -0,0 +1,46 @@
import extensions.
class U0 :: Exception.
class U1 :: Exception.
singleton Exceptions
{
static int i.
bar
<= baz.
baz
[
if (i == 0)
[
U0 new; raise
];
[
U1 new; raise
]
]
foo
[
i := 0.
while (i < 2)
[
try($self bar)
{
on(U0 e)
[
console printLine("U0 Caught").
]
}.
i += 1.
]
]
}
program =
[
Exceptions foo.
].

View file

@ -0,0 +1,28 @@
struct U0 <: Exception end
struct U1 <: Exception end
function foo()
for i in 1:2
try
bar()
catch err
if isa(err, U0) println("catched U0")
else rethrow(err) end
end
end
end
function bar()
baz()
end
function baz()
if isdefined(:_called) && _called
throw(U1())
else
global _called = true
throw(U0())
end
end
foo()

View file

@ -1,30 +1,25 @@
| u0 u1 foo bar baz|
Exception subclass: #U0.
Exception subclass: #U1.
u0 := Signal new.
u1 := Signal new.
Object subclass: Foo [
foo := [
2 timesRepeat:[
[ bar value ]
on: u0
do:[ 'u0 cought' printCR ]
]
].
bazCount := 0.
bar := [
baz value
].
foo
[2 timesRepeat:
[ "==>" [self bar] "<=="
on: U0
do:
[:sig |
'Call to bar was aborted by exception U0' printNl.
sig return]]]
baz := [
|alreadyCalled|
bar
[self baz]
[
alreadyCalled isNil ifTrue:[
alreadyCalled := true. u0 raise
] ifFalse:[
u1 raise
]
]
] value.
foo value
baz
[bazCount := bazCount + 1.
bazCount = 1 ifTrue: [U0 new signal].
bazCount = 2 ifTrue: [U1 new signal].
"Thirds time's a charm..."]
]

View file

@ -1,43 +1,11 @@
Exception
subclass: #U0
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'example'.
Exception
subclass: #U1
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'example'.
Object
subclass: #CatchMeIfYouCan
instanceVariableNames:'bazAlreadyCalled'
classVariableNames:''
poolDictionaries:''
category:'example'.
" CatchMeIfYouCan methods "
foo
2 timesRepeat:[
[ self bar ]
on: U0
do:[ 'U0 cought' printCR ]
]
bar
self baz
baz
bazAlreadyCalled isNil ifTrue:[
bazAlreadyCalled := true.
U0 raise
] ifFalse:[
U1 raise
]
CatchMeIfYouCan new foo
st> Foo new foo
'Call to bar was aborted by exception U0'
Object: Foo new "<-0x4c9a7960>" error: An exception has occurred
U1(Exception)>>signal (ExcHandling.st:254)
Foo>>baz (catch_exception.st:32)
Foo>>bar (catch_exception.st:27)
optimized [] in Foo>>foo (catch_exception.st:19)
BlockClosure>>on:do: (BlkClosure.st:193)
Foo>>foo (catch_exception.st:20)
UndefinedObject>>executeStatements (a String:1)
nil