File: qa-exception

package info (click to toggle)
newlisp 10.7.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,292 kB
  • sloc: ansic: 33,280; lisp: 4,181; sh: 609; makefile: 215
file content (50 lines) | stat: -rwxr-xr-x 969 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env newlisp

; check exception handling with 'catch' and 'throw'

(println)
(println "Testing 'catch' and 'throw'")

(set 'start (time-of-day))

(set 'HI 0 'LO 0)

(define (some_function num)
	(catch (hi_function num) 'result)
	(when (not (integer? result))
		(println "we never get here")))

(define (hi_function num)
	(catch (lo_function num) 'result)
	(if (= result 'HI_exception)
		(++ HI)
		(throw result)))
		
(define (lo_function num)
	(catch (blowup num) 'result)
	(if (= result 'LO_exception) 
		(++ LO)
		(throw result)))

(define (blowup num)
	(if (= (& num 1) 1)
		(throw 'HI_exception)
		(throw 'LO_exception)))

(define (main n)
	(dotimes (i n)
		(some_function i))
	(println "Exceptions: HI=" HI ", LO=" LO))
	

(main 10000)
(println (format " %6.3f ms per exception" (div (sub (time-of-day) start) 10000) ))

(if (= (+ HI LO) 10000)
	(println ">>>>> Exception testing SUCCESSFUL")
	(println ">>>>> PROBLEM in testing exceptions")
)

(exit)