Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
(define (foo)
|
||||
(for ((i 2))
|
||||
(try
|
||||
(bar i)
|
||||
(catch (id message)
|
||||
(if (= id 'U0)
|
||||
(writeln message 'catched)
|
||||
(error id "not catched"))))))
|
||||
|
||||
(define (bar i)
|
||||
(baz i))
|
||||
|
||||
(define (baz i)
|
||||
(if (= i 0)
|
||||
(throw 'U0 "U0 raised")
|
||||
(throw 'U1 "U1 raised")))
|
||||
|
||||
|
||||
(foo) →
|
||||
"U0 raised" catched
|
||||
👓 error: U1 not catched
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Enum ErrorTypes
|
||||
U0 = 1000
|
||||
U1
|
||||
End Enum
|
||||
|
||||
Function errorName(ex As ErrorTypes) As String
|
||||
Select Case As Const ex
|
||||
Case U0
|
||||
Return "U0"
|
||||
Case U1
|
||||
Return "U1"
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Sub catchError(ex As ErrorTypes)
|
||||
Dim e As Integer = Err '' cache the error number
|
||||
If e = ex Then
|
||||
Print "Error "; errorName(ex); ", number"; ex; " caught"
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub baz()
|
||||
Static As Integer timesCalled = 0 '' persisted between procedure calls
|
||||
timesCalled += 1
|
||||
If timesCalled = 1 Then
|
||||
err = U0
|
||||
Else
|
||||
err = U1
|
||||
End if
|
||||
End Sub
|
||||
|
||||
Sub bar()
|
||||
baz
|
||||
End Sub
|
||||
|
||||
Sub foo()
|
||||
bar
|
||||
catchError(U0) '' not interested in U1, assumed non-fatal
|
||||
bar
|
||||
catchError(U0)
|
||||
End Sub
|
||||
|
||||
Foo
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
define try(exception) => {
|
||||
local(
|
||||
gb = givenblock,
|
||||
error
|
||||
)
|
||||
handle => {
|
||||
// Only relay error if it's not the specified exception
|
||||
if(#error) => {
|
||||
if(#error->get(2) == #exception) => {
|
||||
stdoutnl('Handled exception: '+#error->get(2))
|
||||
else
|
||||
stdoutnl('Throwing exception: '+#error->get(2))
|
||||
fail(:#error)
|
||||
}
|
||||
}
|
||||
}
|
||||
protect => {
|
||||
handle_error => {
|
||||
#error = (:error_code,error_msg,error_stack)
|
||||
}
|
||||
#gb()
|
||||
}
|
||||
}
|
||||
|
||||
define foo => {
|
||||
stdoutnl('foo')
|
||||
try('U0') => { bar }
|
||||
try('U0') => { bar }
|
||||
}
|
||||
|
||||
define bar => {
|
||||
stdoutnl('- bar')
|
||||
baz()
|
||||
}
|
||||
|
||||
define baz => {
|
||||
stdoutnl(' - baz')
|
||||
var(bazzed) ? fail('U1') | $bazzed = true
|
||||
fail('U0')
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
type U0 = object of Exception
|
||||
type U1 = object of Exception
|
||||
|
||||
proc baz(i) =
|
||||
if i > 0: raise newException(U1, "Some error")
|
||||
else: raise newException(U0, "Another error")
|
||||
|
||||
proc bar(i) =
|
||||
baz(i)
|
||||
|
||||
proc foo() =
|
||||
for i in 0..1:
|
||||
try:
|
||||
bar(i)
|
||||
except U0:
|
||||
echo "Function foo caught exception U0"
|
||||
|
||||
foo()
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
Exception Class new: U0
|
||||
Exception Class new: U1
|
||||
|
||||
: baz ifZero: [ "First call" U0 throw ] else: [ "Second call" U1 throw ] ;
|
||||
: bar baz ;
|
||||
|
||||
: foo
|
||||
| e |
|
||||
try: e [ 0 bar ] when: [ e isKindOf(U0) ifTrue: [ "Catched" .cr ] else: [ e throw ] ]
|
||||
try: e [ 1 bar ] when: [ e isKindOf(U0) ifTrue: [ "Catched" .cr ] else: [ e throw ] ]
|
||||
"Done" . ;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
func baz(i) { die "U#{i}" };
|
||||
func bar(i) { baz(i) };
|
||||
|
||||
func foo {
|
||||
[0, 1].each { |i|
|
||||
try { bar(i) }
|
||||
catch { |_, msg|
|
||||
msg ~~ /^U0/ ? say "Function foo() caught exception U0"
|
||||
: die msg; # re-raise the exception
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
foo();
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
enum MyException : ErrorType {
|
||||
case U0
|
||||
case U1
|
||||
}
|
||||
|
||||
func foo() throws {
|
||||
for i in 0 ... 1 {
|
||||
do {
|
||||
try bar(i)
|
||||
} catch MyException.U0 {
|
||||
print("Function foo caught exception U0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func bar(i: Int) throws {
|
||||
try baz(i) // Nest those calls
|
||||
}
|
||||
|
||||
func baz(i: Int) throws {
|
||||
if i == 0 {
|
||||
throw MyException.U0
|
||||
} else {
|
||||
throw MyException.U1
|
||||
}
|
||||
}
|
||||
|
||||
try foo()
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# n is assumed to be the number of times baz has been previously called:
|
||||
def baz(n):
|
||||
if n==0 then error("U0")
|
||||
elif n==1 then error("U1")
|
||||
else "Goodbye"
|
||||
end;
|
||||
|
||||
def bar(n): baz(n);
|
||||
|
||||
def foo:
|
||||
(try bar(0) catch if . == "U0" then "We caught U0" else error(.) end),
|
||||
(try bar(1) catch if . == "U0" then "We caught U0" else error(.) end);
|
||||
|
||||
foo
|
||||
Loading…
Add table
Add a link
Reference in a new issue