-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryThrowCatchTest.bb
More file actions
77 lines (59 loc) · 1.66 KB
/
Copy pathTryThrowCatchTest.bb
File metadata and controls
77 lines (59 loc) · 1.66 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Strict
EnableGC
; For calls using function pointers if you need to pass or recieve more than a single integer
; You need to use DTO objects
Type BasicDTO
Field var%
Method create.BasicDTO(var%)
self\var = var
return self
End Method
End Type
Function functionToTry@(dto.BasicDTO=Null)
if (dto = Null)
return FunctionPtr()
end if
Return new BasicDTO(1)
End Function
Function functionToThrow@(dto.BasicDTO=Null)
if (dto = Null)
return FunctionPtr()
end if
Throw new BasicDTO(10)
Return new BasicDTO(1)
End Function
Function functionToCatch@(code.BasicDTO=Null)
if (code = Null)
return FunctionPtr()
end if
Assert(code\var = 10)
return new BasicDTO(2)
End Function
Function nestedFunctionToThrow@(dto.BasicDTO=Null)
if (dto = Null)
return FunctionPtr()
end if
functionToThrow(dto)
return new BasicDTO(3)
End Function
Test testTry()
local dto.BasicDTO = new BasicDTO(0)
local t_func.BBFunction = functionToTry()
local c_func.BBFunction = functionToCatch()
local result.BasicDTO = TryCatch(t_func, c_func, dto)
Assert(result\var = 1)
End Test
Test testCatch()
local dto.BasicDTO = new BasicDTO(0)
local t_func.BBFunction = functionToThrow()
local c_func.BBFunction = functionToCatch()
local result.BasicDTO = TryCatch(t_func, c_func, dto)
Assert(result\var = 2)
End Test
Test testNestedThrow()
local dto.BasicDTO = new BasicDTO(0)
local t_func.BBFunction = nestedFunctionToThrow()
local c_func.BBFunction = functionToCatch()
local result.BasicDTO = TryCatch(t_func, c_func, dto)
Assert(result\var = 2)
End Test