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
30
Task/Exceptions/FreeBASIC/exceptions.freebasic
Normal file
30
Task/Exceptions/FreeBASIC/exceptions.freebasic
Normal 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
|
||||
6
Task/Exceptions/Lasso/exceptions.lasso
Normal file
6
Task/Exceptions/Lasso/exceptions.lasso
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
protect => {
|
||||
handle_error => {
|
||||
// do something else
|
||||
}
|
||||
fail(-1,'Oops')
|
||||
}
|
||||
19
Task/Exceptions/Lingo/exceptions-1.lingo
Normal file
19
Task/Exceptions/Lingo/exceptions-1.lingo
Normal 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
|
||||
4
Task/Exceptions/Lingo/exceptions-2.lingo
Normal file
4
Task/Exceptions/Lingo/exceptions-2.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-- in a movie script
|
||||
on prepareMovie
|
||||
_player.alertHook = script("ErrorHandler")
|
||||
end
|
||||
6
Task/Exceptions/Lingo/exceptions-3.lingo
Normal file
6
Task/Exceptions/Lingo/exceptions-3.lingo
Normal 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
|
||||
1
Task/Exceptions/Nim/exceptions-1.nim
Normal file
1
Task/Exceptions/Nim/exceptions-1.nim
Normal file
|
|
@ -0,0 +1 @@
|
|||
type SillyError = object of Exception
|
||||
2
Task/Exceptions/Nim/exceptions-2.nim
Normal file
2
Task/Exceptions/Nim/exceptions-2.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
proc spam() =
|
||||
raise newException(SillyError, "Some error")
|
||||
8
Task/Exceptions/Nim/exceptions-3.nim
Normal file
8
Task/Exceptions/Nim/exceptions-3.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
try:
|
||||
spam()
|
||||
except SillyError:
|
||||
echo "Got SillyError with message: ", getCurrentExceptionMsg()
|
||||
except:
|
||||
echo "Got another exception"
|
||||
finally:
|
||||
echo "Finally"
|
||||
7
Task/Exceptions/Oforth/exceptions.oforth
Normal file
7
Task/Exceptions/Oforth/exceptions.oforth
Normal 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 ;
|
||||
23
Task/Exceptions/PHL/exceptions.phl
Normal file
23
Task/Exceptions/PHL/exceptions.phl
Normal 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;
|
||||
]
|
||||
5
Task/Exceptions/Ring/exceptions.ring
Normal file
5
Task/Exceptions/Ring/exceptions.ring
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Try
|
||||
see 1/0
|
||||
Catch
|
||||
raise("Sorry we can't divide 1/0 + nl)
|
||||
Done
|
||||
11
Task/Exceptions/Sidef/exceptions.sidef
Normal file
11
Task/Exceptions/Sidef/exceptions.sidef
Normal 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!
|
||||
3
Task/Exceptions/Swift/exceptions-1.swift
Normal file
3
Task/Exceptions/Swift/exceptions-1.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
enum MyException : ErrorType {
|
||||
case TerribleException
|
||||
}
|
||||
3
Task/Exceptions/Swift/exceptions-2.swift
Normal file
3
Task/Exceptions/Swift/exceptions-2.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
func foo() throws {
|
||||
throw MyException.TerribleException
|
||||
}
|
||||
7
Task/Exceptions/Swift/exceptions-3.swift
Normal file
7
Task/Exceptions/Swift/exceptions-3.swift
Normal 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
|
||||
}
|
||||
6
Task/Exceptions/Ursa/exceptions-1.ursa
Normal file
6
Task/Exceptions/Ursa/exceptions-1.ursa
Normal 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
|
||||
1
Task/Exceptions/Ursa/exceptions-2.ursa
Normal file
1
Task/Exceptions/Ursa/exceptions-2.ursa
Normal file
|
|
@ -0,0 +1 @@
|
|||
throw (new ursa.exceptions.exception)
|
||||
1
Task/Exceptions/jq/exceptions-1.jq
Normal file
1
Task/Exceptions/jq/exceptions-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
try FILTER catch CATCHER
|
||||
14
Task/Exceptions/jq/exceptions-2.jq
Normal file
14
Task/Exceptions/jq/exceptions-2.jq
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue