-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevaldebug.html
255 lines (241 loc) · 8.78 KB
/
evaldebug.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Eval() and Debugging — Ring 1.0 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="top" title="Ring 1.0 documentation" href="index.html" />
<link rel="next" title="Demo Programs" href="demo.html" />
<link rel="prev" title="System Functions" href="systemfunc.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="demo.html" title="Demo Programs"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="systemfunc.html" title="System Functions"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Ring 1.0 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="eval-and-debugging">
<h1>Eval() and Debugging<a class="headerlink" href="#eval-and-debugging" title="Permalink to this headline">¶</a></h1>
<p id="index-0">In this chapter we are going to learn about</p>
<ul class="simple">
<li>Error Handling using Try/Catch/Done</li>
<li>Eval() function</li>
<li>Raise() function</li>
<li>Assert() function</li>
</ul>
<div class="section" id="try-catch-done">
<span id="index-1"></span><h2>Try/Catch/Done<a class="headerlink" href="#try-catch-done" title="Permalink to this headline">¶</a></h2>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Try
Statements...
Catch
Statements...
Done
</pre></div>
</div>
<p>The statements in the Try block will be executed, if any error happens then
the statements in the catch block will be executed.</p>
<p>Inside the catch block we can use the variable cCatchError to get the error message</p>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>Try
see 5/0
Catch
see "Catch!" + nl + cCatchError
Done
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>Catch!
Error (R1) : Cann't divide by zero !
</pre></div>
</div>
</div>
<div class="section" id="eval-function">
<span id="index-2"></span><h2>Eval() Function<a class="headerlink" href="#eval-function" title="Permalink to this headline">¶</a></h2>
<p>We can execute code during the runtime from string using the Eval() function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Eval(cCode)
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>Eval("nOutput = 5+2*5 " )
See "5+2*5 = " + nOutput + nl
Eval("for x = 1 to 10 see x + nl next")
Eval("func test see 'message from test!' ")
test()
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>5+2*5 = 15
1
2
3
4
5
6
7
8
9
10
message from test!
</pre></div>
</div>
</div>
<div class="section" id="raise-function">
<span id="index-3"></span><h2>Raise() Function<a class="headerlink" href="#raise-function" title="Permalink to this headline">¶</a></h2>
<p>We can raise an exception using the Raise() function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Raise(cErrorMessage)
</pre></div>
</div>
<p>The function will display the error message then end the execution of the program.</p>
<p>We can use Try/Catch/Done to avoid exceptions generated by raise() function.</p>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>nMode = 10
if nMode < 0 or nMode > 5
raise("Error : nMode not in the range 1:4")
ok
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>Line 4 Error : nMode not in the range 1:4
In raise in file tests\raise.ring
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>try
testmode(6)
catch
see "avoid raise!"
done
testmode(-1)
func testmode nMode
if nMode < 0 or nMode > 5
raise("Error : nMode not in the range 1:4")
ok
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>avoid raise!
Line 12 Error : nMode not in the range 1:4
In raise In function testmode() in file tests\raise2.ring
called from line 7 in file tests\raise2.ring
</pre></div>
</div>
</div>
<div class="section" id="assert-function">
<span id="index-4"></span><h2>Assert() Function<a class="headerlink" href="#assert-function" title="Permalink to this headline">¶</a></h2>
<p>We can use the Assert() function to test conditions before executing the code</p>
<p>If the test fail the program will be terminated with an error message contains the assert condition.</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Assert( condition )
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>x = 10
assert( x = 10)
assert( x = 100 )
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>Line 3 Assertion Failed!
In assert in file tests\assert.ring
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Eval() and Debugging</a><ul>
<li><a class="reference internal" href="#try-catch-done">Try/Catch/Done</a></li>
<li><a class="reference internal" href="#eval-function">Eval() Function</a></li>
<li><a class="reference internal" href="#raise-function">Raise() Function</a></li>
<li><a class="reference internal" href="#assert-function">Assert() Function</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="systemfunc.html"
title="previous chapter">System Functions</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="demo.html"
title="next chapter">Demo Programs</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/evaldebug.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="demo.html" title="Demo Programs"
>next</a> |</li>
<li class="right" >
<a href="systemfunc.html" title="System Functions"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Ring 1.0 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2016, Mahmoud Samir Fayed.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>