A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
4
Task/Exceptions/Factor/exceptions-1.factor
Normal file
4
Task/Exceptions/Factor/exceptions-1.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"Install Linux, Problem Solved" throw
|
||||
|
||||
TUPLE: velociraptor ;
|
||||
\ velociraptor new throw
|
||||
2
Task/Exceptions/Factor/exceptions-2.factor
Normal file
2
Task/Exceptions/Factor/exceptions-2.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ERROR: velociraptor ;
|
||||
velociraptor
|
||||
12
Task/Exceptions/Factor/exceptions-3.factor
Normal file
12
Task/Exceptions/Factor/exceptions-3.factor
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
! Preferred exception handling
|
||||
: try-foo
|
||||
[ foo ] [ foo-failed ] recover ;
|
||||
|
||||
: try-bar
|
||||
[ bar ] [ bar-errored ] [ bar-always ] cleanup ;
|
||||
|
||||
! Used rarely
|
||||
[ "Fail" throw ] try ! throws a "Fail"
|
||||
[ "Fail" throw ] catch ! returns "Fail"
|
||||
[ "Hi" print ] catch ! returns f (looks the same as throwing f; don't throw f)
|
||||
[ f throw ] catch ! returns f, bad! use recover or cleanup instead
|
||||
20
Task/Exceptions/Fancy/exceptions.fancy
Normal file
20
Task/Exceptions/Fancy/exceptions.fancy
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# define custom exception class
|
||||
# StandardError is base class for all exception classes
|
||||
class MyError : StandardError {
|
||||
def initialize: message {
|
||||
# forward to StdError's initialize method
|
||||
super initialize: message
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
# raises/throws a new MyError exception within try-block
|
||||
MyError new: "my message" . raise!
|
||||
} catch MyError => e {
|
||||
# catch exception
|
||||
# this will print "my message"
|
||||
e message println
|
||||
} finally {
|
||||
# this will always be executed (as in e.g. Java)
|
||||
"This is how exception handling in Fancy works :)" println
|
||||
}
|
||||
23
Task/Exceptions/Fantom/exceptions.fantom
Normal file
23
Task/Exceptions/Fantom/exceptions.fantom
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Create a new error class by subclassing sys::Err
|
||||
const class SpecialErr : Err
|
||||
{
|
||||
// you must provide some message about the error
|
||||
// to the parent class, for reporting
|
||||
new make () : super ("special error") {}
|
||||
}
|
||||
|
||||
class Main
|
||||
{
|
||||
static Void fn ()
|
||||
{
|
||||
throw SpecialErr ()
|
||||
}
|
||||
|
||||
public static Void main ()
|
||||
{
|
||||
try
|
||||
fn()
|
||||
catch (SpecialErr e)
|
||||
echo ("Caught " + e)
|
||||
}
|
||||
}
|
||||
18
Task/Exceptions/J/exceptions.j
Normal file
18
Task/Exceptions/J/exceptions.j
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
pickyPicky =: verb define
|
||||
if. y-:'bad argument' do.
|
||||
throw.
|
||||
else.
|
||||
'thanks!'
|
||||
end.
|
||||
)
|
||||
|
||||
tryThis =: verb define
|
||||
try.
|
||||
pickyPicky y
|
||||
catcht.
|
||||
'Uh oh!'
|
||||
end.
|
||||
)
|
||||
|
||||
tryThis 'bad argument'
|
||||
Uh oh!
|
||||
7
Task/Exceptions/Logo/exceptions.logo
Normal file
7
Task/Exceptions/Logo/exceptions.logo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
to div.checked :a :b
|
||||
if :b = 0 [(throw "divzero 0)]
|
||||
output :a / :b
|
||||
end
|
||||
to div.safely :a :b
|
||||
output catch "divzero [div.checked :a :b]
|
||||
end
|
||||
1
Task/Exceptions/MOO/exceptions-1.moo
Normal file
1
Task/Exceptions/MOO/exceptions-1.moo
Normal file
|
|
@ -0,0 +1 @@
|
|||
raise(E_PERM);
|
||||
5
Task/Exceptions/MOO/exceptions-2.moo
Normal file
5
Task/Exceptions/MOO/exceptions-2.moo
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
try
|
||||
this:foo();
|
||||
except e (ANY)
|
||||
this:bar(e);
|
||||
endtry
|
||||
5
Task/Exceptions/MOO/exceptions-3.moo
Normal file
5
Task/Exceptions/MOO/exceptions-3.moo
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
try
|
||||
this:foo();
|
||||
finally
|
||||
this:bar();
|
||||
endtry
|
||||
1
Task/Exceptions/MOO/exceptions-4.moo
Normal file
1
Task/Exceptions/MOO/exceptions-4.moo
Normal file
|
|
@ -0,0 +1 @@
|
|||
`this:foo()!ANY=>this:bar()';
|
||||
2
Task/Exceptions/Make/exceptions-1.make
Normal file
2
Task/Exceptions/Make/exceptions-1.make
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
false
|
||||
2
Task/Exceptions/Make/exceptions-2.make
Normal file
2
Task/Exceptions/Make/exceptions-2.make
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
-@make -f fail.mk
|
||||
2
Task/Exceptions/Make/exceptions-3.make
Normal file
2
Task/Exceptions/Make/exceptions-3.make
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
make -f fail.mk; exit 0
|
||||
8
Task/Exceptions/Mathematica/exceptions.mathematica
Normal file
8
Task/Exceptions/Mathematica/exceptions.mathematica
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
f[x_] := If[x > 10, Throw[overflow], x!]
|
||||
|
||||
Example usage :
|
||||
Catch[f[2] + f[11]]
|
||||
-> overflow
|
||||
|
||||
Catch[f[2] + f[3]]
|
||||
-> 8
|
||||
2
Task/Exceptions/Modula-3/exceptions-1.mod3
Normal file
2
Task/Exceptions/Modula-3/exceptions-1.mod3
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
EXCEPTION EndOfFile;
|
||||
EXCEPTION Error(TEXT);
|
||||
4
Task/Exceptions/Modula-3/exceptions-2.mod3
Normal file
4
Task/Exceptions/Modula-3/exceptions-2.mod3
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
PROCEDURE Foo() RAISES { EndOfFile } =
|
||||
...
|
||||
RAISE EndOfFile;
|
||||
...
|
||||
5
Task/Exceptions/Modula-3/exceptions-3.mod3
Normal file
5
Task/Exceptions/Modula-3/exceptions-3.mod3
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TRY
|
||||
Foo();
|
||||
EXCEPT
|
||||
| EndOfFile => HandleFoo();
|
||||
END;
|
||||
5
Task/Exceptions/Modula-3/exceptions-4.mod3
Normal file
5
Task/Exceptions/Modula-3/exceptions-4.mod3
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TRY
|
||||
Foo();
|
||||
FINALLY
|
||||
CleanupFoo(); (* always executed *)
|
||||
END;
|
||||
Loading…
Add table
Add a link
Reference in a new issue