root/NEWT0/trunk/sample/exception.newt

Revision 1, 0.6 kB (checked in by gnue, 4 years ago)

import project

Line 
1#!newt
2
3begin
4    // Catch built-in.
5    try
6        5 / 0;
7    onexception |evt.ex.fr| do
8        Print("Caught built-in\n");
9
10    // Catch custom.
11    try
12        Throw('|evt.ex.foo|, nil);
13    onexception |evt.ex.foo| do
14        Print("Caught custom\n");
15
16    // Catch custom with data.
17    try
18        Throw('|evt.ex.foo;type.ref.frame|, {});
19    onexception |evt.ex.foo| do
20        Print("Caught custom with data\n");
21   
22    // Catch and print data.
23    try
24        Throw('|evt.ex.foo;type.ref.string|, "Some data");
25    onexception |evt.ex.foo| do
26        Print("Caught: " & CurrentException().data & "\n");
27   
28    // Don't catch.
29    try
30        throw('|evt.ex.foo|, nil);
31    onexception |evt.ex.msg| do nil;
32end;
Note: See TracBrowser for help on using the browser.