langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
28
Task/Exceptions/NetRexx/exceptions.netrexx
Normal file
28
Task/Exceptions/NetRexx/exceptions.netrexx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
-- =============================================================================
|
||||
class RExceptions public
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method test() public signals RExceptions.TakeException
|
||||
if (1 == 1) then signal RExceptions.TakeException()
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method main(args = String[]) public static
|
||||
do
|
||||
RExceptions().test()
|
||||
catch ex = Exception
|
||||
say ex.toString()
|
||||
end
|
||||
|
||||
return;
|
||||
|
||||
-- =============================================================================
|
||||
class RExceptions.TakeException public extends Exception
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method TakeException() public
|
||||
super('I resent that!')
|
||||
return
|
||||
2
Task/Exceptions/OCaml/exceptions-1.ocaml
Normal file
2
Task/Exceptions/OCaml/exceptions-1.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
exception My_Exception;;
|
||||
exception Another_Exception of string;;
|
||||
6
Task/Exceptions/OCaml/exceptions-2.ocaml
Normal file
6
Task/Exceptions/OCaml/exceptions-2.ocaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let foo x =
|
||||
match x with
|
||||
1 -> raise My_Exception
|
||||
| 2 -> raise (Another_Exception "hi mom")
|
||||
| _ -> 5
|
||||
;;
|
||||
6
Task/Exceptions/OCaml/exceptions-3.ocaml
Normal file
6
Task/Exceptions/OCaml/exceptions-3.ocaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
try
|
||||
string_of_int (foo 2)
|
||||
with
|
||||
My_Exception -> "got my exception"
|
||||
| Another_Exception s -> s
|
||||
| _ -> "unknown exception"
|
||||
4
Task/Exceptions/Objective-C/exceptions-1.m
Normal file
4
Task/Exceptions/Objective-C/exceptions-1.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@interface MyException : NSException {
|
||||
//Put specific info in here
|
||||
}
|
||||
@end
|
||||
4
Task/Exceptions/Objective-C/exceptions-2.m
Normal file
4
Task/Exceptions/Objective-C/exceptions-2.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
- (void)foo {
|
||||
@throw [NSException exceptionWithName:@"TerribleException"
|
||||
reason:@"OMGWTFBBQ111!1" userInfo:nil];
|
||||
}
|
||||
16
Task/Exceptions/Objective-C/exceptions-3.m
Normal file
16
Task/Exceptions/Objective-C/exceptions-3.m
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
@try {
|
||||
[self foo];
|
||||
}
|
||||
@catch (MyException *exc) {
|
||||
//Catch only your specified type of exception
|
||||
}
|
||||
@catch (NSException *exc) {
|
||||
//Catch any NSException or subclass
|
||||
NSLog(@"caught exception named %@, with reason: %@", [exc name], [exc reason]);
|
||||
}
|
||||
@catch (id exc) {
|
||||
//Catch any kind of object
|
||||
}
|
||||
@finally {
|
||||
//This code is always executed after exiting the try block
|
||||
}
|
||||
2
Task/Exceptions/Oz/exceptions-1.oz
Normal file
2
Task/Exceptions/Oz/exceptions-1.oz
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
raise sillyError end
|
||||
raise slightlyLessSilly(data:42 reason:outOfMemory) end
|
||||
5
Task/Exceptions/Oz/exceptions-2.oz
Normal file
5
Task/Exceptions/Oz/exceptions-2.oz
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
try
|
||||
raise someError(debug:unit) end
|
||||
catch someError(debug:d(stack:ST ...)...) then
|
||||
{Inspect ST}
|
||||
end
|
||||
11
Task/Exceptions/Oz/exceptions-3.oz
Normal file
11
Task/Exceptions/Oz/exceptions-3.oz
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
try
|
||||
{Foo}
|
||||
catch sillyError then
|
||||
{Bar}
|
||||
[] slightlyLessSilly(data:D ...) then
|
||||
{Quux D}
|
||||
[] _ then %% an unknown type of exception was thrown
|
||||
{Baz}
|
||||
finally
|
||||
{Fin}
|
||||
end
|
||||
5
Task/Exceptions/PARI-GP/exceptions-1.pari
Normal file
5
Task/Exceptions/PARI-GP/exceptions-1.pari
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
trap(/* specific error can be given here, or leave blank to catch all */,
|
||||
"caught"
|
||||
,
|
||||
error("bad stuff")
|
||||
)
|
||||
1
Task/Exceptions/PARI-GP/exceptions-2.pari
Normal file
1
Task/Exceptions/PARI-GP/exceptions-2.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
error("Text of error here")
|
||||
1
Task/Exceptions/PARI-GP/exceptions-3.pari
Normal file
1
Task/Exceptions/PARI-GP/exceptions-3.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
pari_err(arither1, "functionName"); // Gives "*** functionName: not an integer argument in an arithmetic function"
|
||||
3
Task/Exceptions/PARI-GP/exceptions-4.pari
Normal file
3
Task/Exceptions/PARI-GP/exceptions-4.pari
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
GEN x = closure_trapgen(arither1, f); // Executes the function f, catching "not an integer argument in an arithmetic function" errors
|
||||
if (x == (GEN)1L) // Was there an error?
|
||||
pari_printf("Don't do that!\n"); // Recover
|
||||
11
Task/Exceptions/PL-I/exceptions.pli
Normal file
11
Task/Exceptions/PL-I/exceptions.pli
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* Define a new exception, called "my_condition". */
|
||||
on condition (my_condition) snap begin;
|
||||
put skip list ('My condition raised.');
|
||||
end;
|
||||
|
||||
/* Raise that exception */
|
||||
signal condition (my_condition);
|
||||
|
||||
/* Raising that exception causes the message "My condition raised" */
|
||||
/* to be printed, and execution then resumes at the statement */
|
||||
/* following the SIGNAL statement. */
|
||||
9
Task/Exceptions/Perl-6/exceptions.pl6
Normal file
9
Task/Exceptions/Perl-6/exceptions.pl6
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
try { die "Help I'm dieing!"; CATCH { note $_.uc; say "Cough, Cough, Aiee!!" } }
|
||||
|
||||
CATCH { note "No you're not."; say $_; }
|
||||
|
||||
say "Yay. I'm alive.";
|
||||
|
||||
die "I'm dead.";
|
||||
|
||||
say "Arrgh.";
|
||||
3
Task/Exceptions/Pop11/exceptions-1.pop11
Normal file
3
Task/Exceptions/Pop11/exceptions-1.pop11
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
define throw_exception();
|
||||
throw([my_exception my_data]);
|
||||
enddefine;
|
||||
10
Task/Exceptions/Pop11/exceptions-2.pop11
Normal file
10
Task/Exceptions/Pop11/exceptions-2.pop11
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
define main();
|
||||
vars cargo;
|
||||
define catcher();
|
||||
;;; print exception data
|
||||
cargo =>
|
||||
enddefine;
|
||||
catch(throw_exception, catcher, [my_exception ?cargo]);
|
||||
enddefine;
|
||||
|
||||
main();
|
||||
9
Task/Exceptions/PureBasic/exceptions.purebasic
Normal file
9
Task/Exceptions/PureBasic/exceptions.purebasic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Procedure ErrorHandler()
|
||||
MessageRequester("Exception test", "The following error happened: " + ErrorMessage())
|
||||
EndProcedure
|
||||
|
||||
MessageRequester("Exception test", "Test start")
|
||||
|
||||
OnErrorCall(@ErrorHandler())
|
||||
|
||||
RaiseError(#PB_OnError_InvalidMemory) ;a custom error# can also be used here depending on the OS being compiled for
|
||||
10
Task/Exceptions/Raven/exceptions.raven
Normal file
10
Task/Exceptions/Raven/exceptions.raven
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
42 as custom_error
|
||||
|
||||
define foo
|
||||
custom_error throw
|
||||
|
||||
try
|
||||
foo
|
||||
catch
|
||||
custom_error =
|
||||
if 'oops' print
|
||||
4
Task/Exceptions/Slate/exceptions-1.slate
Normal file
4
Task/Exceptions/Slate/exceptions-1.slate
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
se@(SceneElement traits) doWithRestart: block
|
||||
[
|
||||
block handlingCases: {Abort -> [| :_ | ^ Nil]}
|
||||
].
|
||||
18
Task/Exceptions/Slate/exceptions-2.slate
Normal file
18
Task/Exceptions/Slate/exceptions-2.slate
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
conditions define: #Abort &parents: {Restart}.
|
||||
"An Abort is a Restart which exits the computation, unwinding the stack."
|
||||
|
||||
_@lobby abort
|
||||
[
|
||||
Abort signal
|
||||
].
|
||||
_@(Abort traits) describeOn: console
|
||||
[
|
||||
console ; 'Abort evaluation of expression\n'
|
||||
].
|
||||
|
||||
"This will call:"
|
||||
c@(Condition traits) signal
|
||||
"Signalling a Condition."
|
||||
[
|
||||
c tryHandlers
|
||||
].
|
||||
1
Task/Exceptions/Slate/exceptions-3.slate
Normal file
1
Task/Exceptions/Slate/exceptions-3.slate
Normal file
|
|
@ -0,0 +1 @@
|
|||
(fileName endsWith: '.image') ifTrue: [error: 'Image filename specified where Slate source expected. Make sure you run slate with the -i flag to specify an image.'].
|
||||
2
Task/Exceptions/Standard-ML/exceptions-1.ml
Normal file
2
Task/Exceptions/Standard-ML/exceptions-1.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
exception MyException;
|
||||
exception MyDataException of int; (* can be any first-class type, not just int *)
|
||||
2
Task/Exceptions/Standard-ML/exceptions-2.ml
Normal file
2
Task/Exceptions/Standard-ML/exceptions-2.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fun f() = raise MyException;
|
||||
fun g() = raise MyDataException 22;
|
||||
2
Task/Exceptions/Standard-ML/exceptions-3.ml
Normal file
2
Task/Exceptions/Standard-ML/exceptions-3.ml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
val x = f() handle MyException => 22;
|
||||
val y = f() handle MyDataException x => x;
|
||||
22
Task/Exceptions/TXR/exceptions.txr
Normal file
22
Task/Exceptions/TXR/exceptions.txr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
@(defex gorilla ape primate)
|
||||
@(defex monkey primate)
|
||||
@(defex human primate)
|
||||
@(collect)
|
||||
@(try)
|
||||
@(cases)
|
||||
gorilla @name
|
||||
@(throw gorilla name)
|
||||
@(or)
|
||||
monkey @name
|
||||
@(throw monkey name)
|
||||
@(or)
|
||||
human @name
|
||||
@(throw human name)
|
||||
@(end)@#cases
|
||||
@(catch primate (name))
|
||||
@kind @name
|
||||
@(output)
|
||||
we have a primate @name of kind @kind
|
||||
@(end)@#output
|
||||
@(end)@#try
|
||||
@(end)@#collect
|
||||
5
Task/Exceptions/Ursala/exceptions.ursala
Normal file
5
Task/Exceptions/Ursala/exceptions.ursala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#import std
|
||||
|
||||
thrower = ~&?/'success'! -[epic fail]-!%
|
||||
|
||||
catcher = guard(thrower,---[someone failed]-)
|
||||
4
Task/Exceptions/V/exceptions-1.v
Normal file
4
Task/Exceptions/V/exceptions-1.v
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[myproc
|
||||
['new error' 1 2 3] throw
|
||||
'should not come here' puts
|
||||
].
|
||||
2
Task/Exceptions/V/exceptions-2.v
Normal file
2
Task/Exceptions/V/exceptions-2.v
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[myproc] [puts] catch
|
||||
=[new error 1 2 3]
|
||||
4
Task/Exceptions/Visual-Basic-.NET/exceptions-1.visual
Normal file
4
Task/Exceptions/Visual-Basic-.NET/exceptions-1.visual
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Class MyException
|
||||
Inherits Exception
|
||||
'data with info about exception
|
||||
End Class
|
||||
3
Task/Exceptions/Visual-Basic-.NET/exceptions-2.visual
Normal file
3
Task/Exceptions/Visual-Basic-.NET/exceptions-2.visual
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Sub foo()
|
||||
Throw New MyException
|
||||
End Sub
|
||||
13
Task/Exceptions/Visual-Basic-.NET/exceptions-3.visual
Normal file
13
Task/Exceptions/Visual-Basic-.NET/exceptions-3.visual
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Sub bar()
|
||||
Try
|
||||
foo()
|
||||
Catch e As MyException When e.Data.Contains("Foo")
|
||||
' handle exceptions of type MyException when the exception contains specific data
|
||||
Catch e As MyException
|
||||
' handle exceptions of type MyException and derived exceptions
|
||||
Catch e As Exception
|
||||
' handle any type of exception not handled by above catches
|
||||
Finally
|
||||
'code here occurs whether or not there was an exception
|
||||
End Try
|
||||
End Sub
|
||||
7
Task/Exceptions/Visual-Basic/exceptions-1.vb
Normal file
7
Task/Exceptions/Visual-Basic/exceptions-1.vb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Sub foo1()
|
||||
err.raise(vbObjectError + 1050)
|
||||
End Sub
|
||||
|
||||
Sub foo2()
|
||||
Error vbObjectError + 1051
|
||||
End Sub
|
||||
40
Task/Exceptions/Visual-Basic/exceptions-2.vb
Normal file
40
Task/Exceptions/Visual-Basic/exceptions-2.vb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
Sub bar1()
|
||||
'by convention, a simple handler
|
||||
On Error Goto Catch
|
||||
fooX
|
||||
Exit Sub
|
||||
Catch:
|
||||
'handle all exceptions
|
||||
Exit Sub
|
||||
|
||||
Sub bar2()
|
||||
'a more complex handler, illustrating some of the flexibility of VBA exception handling
|
||||
on error goto catch
|
||||
100 fooX
|
||||
200 fooY
|
||||
'finally block may be placed anywhere: this is complexity for it's own sake:
|
||||
goto finally
|
||||
|
||||
catch:
|
||||
if erl= 100 then
|
||||
' handle exception at first line: in this case, by ignoring it:
|
||||
resume next
|
||||
else
|
||||
select case err.nummber
|
||||
case vbObjectError + 1050
|
||||
' handle exceptions of type 1050
|
||||
case vbObjectError + 1051
|
||||
' handle exceptions of type 1051
|
||||
case else
|
||||
' handle any type of exception not handled by above catches or line numbers
|
||||
resume finally
|
||||
|
||||
finally:
|
||||
'code here occurs whether or not there was an exception
|
||||
'block may be placed anywhere
|
||||
'by convention, often just a drop through to an Exit Sub, rather tnan a code block
|
||||
Goto end_try:
|
||||
|
||||
end_try:
|
||||
'by convention, often just a drop through from the catch block
|
||||
exit sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue