Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,30 @@
' FB 1.05.0 Win64
Enum ErrorType
myError = 1000
End Enum
Sub foo()
Err = 1000 ' raise a user-defined error
End Sub
Sub callFoo()
foo()
Dim As Long errNo = Err ' cache Err in case it's reset by a different function
Select Case errNo
Case 0
' No error (system defined)
Case 1 To 17
' System defined runtime errors
Case myError: ' catch myError
Print "Caught myError : Error number"; errNo
Case Else
' catch any other type of errors here
End Select
' add any clean-up code here
End Sub
callfoo()
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,6 @@
protect => {
handle_error => {
// do something else
}
fail(-1,'Oops')
}

View file

@ -0,0 +1,19 @@
-- parent script "ErrorHandler"
on alertHook (me, errorType, errorMessage, alertType)
if alertType=#alert then return 0 -- ignore programmatic alerts
-- log error in file "error.log"
fn = _movie.path&"error.log"
fp = xtra("fileIO").new()
fp.openFile(fn, 2)
if fp.status() = -37 then
fp.createFile(fn)
fp.openFile(fn, 2)
end if
fp.setPosition(fp.getLength())
fp.writeString(_system.date() && _system.time() && errorType & ": " & errorMessage & RETURN)
fp.closeFile()
return 1 -- continues movie playback, no error dialog
end

View file

@ -0,0 +1,4 @@
-- in a movie script
on prepareMovie
_player.alertHook = script("ErrorHandler")
end

View file

@ -0,0 +1,6 @@
-- in a movie script
-- usage: throw("Custom error 23")
on throw (msg)
_player.alertHook.alertHook("Script runtime error", msg, #script)
abort() -- exits call stack
end

View file

@ -0,0 +1 @@
type SillyError = object of Exception

View file

@ -0,0 +1,2 @@
proc spam() =
raise newException(SillyError, "Some error")

View file

@ -0,0 +1,8 @@
try:
spam()
except SillyError:
echo "Got SillyError with message: ", getCurrentExceptionMsg()
except:
echo "Got another exception"
finally:
echo "Finally"

View file

@ -0,0 +1,7 @@
: iwillThrowAnException "A new exception" Exception throw ;
: iwillCatch
| e |
try: e [ iwillThrowAnException ] when: [ "Exception catched :" . e .cr ]
try: e [ 1 2 over last ] when: [ "Exception catched :" . e .cr ]
"Done" println ;

View file

@ -0,0 +1,23 @@
module exceptions;
extern printf;
struct @MyException : @Exception {
};
@Void func throws ex [
throw new @MyException;
]
@Integer main [
try func();
catch (e) {
if (e::getType == "MyException") {
printf("MyException thrown!\n");
} else {
printf("Unhandled exception!\n");
}
}
return 0;
]

View file

@ -0,0 +1,5 @@
Try
see 1/0
Catch
raise("Sorry we can't divide 1/0 + nl)
Done

View file

@ -0,0 +1,11 @@
try {
die "I'm dead!"; # throws an exception of type 'error'
}
catch { |type, msg|
say "type: #{type}"; # type: error
say "msg: #{msg}"; # msg: I'm dead! at test.sf line 2.
};
say "I'm alive...";
die "Now I'm dead!"; # this line terminates the program
say "Or am I?"; # Yes, you are!

View file

@ -0,0 +1,3 @@
enum MyException : ErrorType {
case TerribleException
}

View file

@ -0,0 +1,3 @@
func foo() throws {
throw MyException.TerribleException
}

View file

@ -0,0 +1,7 @@
do {
try foo()
} catch MyException.TerribleException { // this can be any pattern
//Catch a specific case of exception
} catch {
//Catch any exception
}

View file

@ -0,0 +1,6 @@
try
invalid "this statement will fail"
catch syntaxerror
# console.err is optional here
out "caught an exception" endl console.err
end try

View file

@ -0,0 +1 @@
throw (new ursa.exceptions.exception)

View file

@ -0,0 +1 @@
try FILTER catch CATCHER

View file

@ -0,0 +1,14 @@
def division(a;b):
def abs: if . < 0 then -. else . end;
if a == 0 and b == 0 then error("0/0")
elif b == 0 then error("division by 0")
elif (a|abs|log) - (b|abs|log) > 700 then error("OOB")
else a/b
end;
def test(a;b):
try division(a;b)
catch if . == "0/0" then 0
elif . == "division by 0" then null
else "\(.): \(a) / \(b)"
end;