langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View 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

View file

@ -0,0 +1,2 @@
exception My_Exception;;
exception Another_Exception of string;;

View file

@ -0,0 +1,6 @@
let foo x =
match x with
1 -> raise My_Exception
| 2 -> raise (Another_Exception "hi mom")
| _ -> 5
;;

View file

@ -0,0 +1,6 @@
try
string_of_int (foo 2)
with
My_Exception -> "got my exception"
| Another_Exception s -> s
| _ -> "unknown exception"

View file

@ -0,0 +1,4 @@
@interface MyException : NSException {
//Put specific info in here
}
@end

View file

@ -0,0 +1,4 @@
- (void)foo {
@throw [NSException exceptionWithName:@"TerribleException"
reason:@"OMGWTFBBQ111!1" userInfo:nil];
}

View 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
}

View file

@ -0,0 +1,2 @@
raise sillyError end
raise slightlyLessSilly(data:42 reason:outOfMemory) end

View file

@ -0,0 +1,5 @@
try
raise someError(debug:unit) end
catch someError(debug:d(stack:ST ...)...) then
{Inspect ST}
end

View 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

View file

@ -0,0 +1,5 @@
trap(/* specific error can be given here, or leave blank to catch all */,
"caught"
,
error("bad stuff")
)

View file

@ -0,0 +1 @@
error("Text of error here")

View file

@ -0,0 +1 @@
pari_err(arither1, "functionName"); // Gives "*** functionName: not an integer argument in an arithmetic function"

View 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

View 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. */

View 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.";

View file

@ -0,0 +1,3 @@
define throw_exception();
throw([my_exception my_data]);
enddefine;

View 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();

View 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

View file

@ -0,0 +1,10 @@
42 as custom_error
define foo
custom_error throw
try
foo
catch
custom_error =
if 'oops' print

View file

@ -0,0 +1,4 @@
se@(SceneElement traits) doWithRestart: block
[
block handlingCases: {Abort -> [| :_ | ^ Nil]}
].

View 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
].

View 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.'].

View file

@ -0,0 +1,2 @@
exception MyException;
exception MyDataException of int; (* can be any first-class type, not just int *)

View file

@ -0,0 +1,2 @@
fun f() = raise MyException;
fun g() = raise MyDataException 22;

View file

@ -0,0 +1,2 @@
val x = f() handle MyException => 22;
val y = f() handle MyDataException x => x;

View 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

View file

@ -0,0 +1,5 @@
#import std
thrower = ~&?/'success'! -[epic fail]-!%
catcher = guard(thrower,---[someone failed]-)

View file

@ -0,0 +1,4 @@
[myproc
['new error' 1 2 3] throw
'should not come here' puts
].

View file

@ -0,0 +1,2 @@
[myproc] [puts] catch
=[new error 1 2 3]

View file

@ -0,0 +1,4 @@
Class MyException
Inherits Exception
'data with info about exception
End Class

View file

@ -0,0 +1,3 @@
Sub foo()
Throw New MyException
End Sub

View 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

View file

@ -0,0 +1,7 @@
Sub foo1()
err.raise(vbObjectError + 1050)
End Sub
Sub foo2()
Error vbObjectError + 1051
End Sub

View 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