-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1426.html
More file actions
165 lines (165 loc) · 9.73 KB
/
Copy path1426.html
File metadata and controls
165 lines (165 loc) · 9.73 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | CATCH</title>
<meta name="description" content="The CATCH statement is used to CATCH an run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file. The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.">
<link rel="canonical" href="1426">
<link rel="keywords" href="CATCH [var | expr]">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a href="/pages/articles.html">Resources</a>
<a class='active' href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/reference/1426-language-catch.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/reference/1426-language-catch.markdown">History</a>
</div>
</div>
<div class="article">
<h1>CATCH</h1>
<blockquote>CATCH [var | expr]</blockquote>
<div class="siteSub">
<p>
<a href="/">Home</a> >
<a href="/pages/reference.html">Reference</a> >
<a href="/pages/language.html">Language</a>
</p>
</div>
<p>The CATCH statement is used to catch a run-time error. This is
typically used with errors raised when calling a file system command
that cannot be completed, for example attempting to open a non-existent
file.</p>
<p>The CATCH statement has two modes. You can supply a variable argument
to store the error string. Alternatively you can supply an expression.
When the raised error matches the (String) expression, the error will be
caught. When using the expression mode, you can supply a succession of
CATCH statements to handle various error messages separately.</p>
<p>For more information see TRY.</p>
<h3 id="example">Example</h3>
<div class="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">try</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="co">' DON'T use existing file for demo.</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">open</span> <span class="st">"try demo.tmp"</span> <span class="kw">for input </span> <span class="kw">as</span> #<span class="dv">1</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="kw">catch</span> err</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> err</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="co">' Some error handling could be implemented here</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="co">' i.e: if(err = "...") then ...</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="kw">end try</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="kw">print</span> <span class="st">"This point is reach, even if opening the file was not possible"</span></span></code></pre></div>
<div class="lavenderBox">
<div class="header">Code samples using CATCH</div>
<div class="linklist">
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 2/3d rotating cube with message.bas">3d rotating cube with message.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/code demos/draw button test.bas">draw button test.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/system/new bas.bas">new bas.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/system/quick key code.bas">quick key code.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 3/raycaster.bas">raycaster.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/raycaster.bas">raycaster.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 3/sensor.bas">sensor.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/water.bas">water.bas </a>
</div>
</div>
<div class="lavenderBox">
<div class="header">Language</div>
<div class="linklist">
<a href="/reference/662.html">AND </a>
<a href="/reference/1424.html">AS </a>
<a href="/reference/663.html">BAND </a>
<a href="/reference/1428.html">BG </a>
<a href="/reference/664.html">BOR </a>
<a href="/reference/639.html">BYREF </a>
<a href="/reference/637.html">CALL </a>
<a href="/reference/640.html">CASE </a>
<a href="/reference/1426.html"><strong>CATCH</strong> </a>
<a href="/reference/678.html">CONST </a>
<a href="/reference/1419.html">DECLARE </a>
<a href="/reference/641.html">DEF </a>
<a href="/reference/642.html">DO </a>
<a href="/reference/643.html">ELIF </a>
<a href="/reference/644.html">ELSE </a>
<a href="/reference/645.html">ELSEIF </a>
<a href="/reference/679.html">END </a>
<a href="/reference/1427.html">END TRY </a>
<a href="/reference/646.html">ENDIF </a>
<a href="/reference/665.html">EQV </a>
<a href="/reference/648.html">EXIT </a>
<a href="/reference/1457.html">FALSE </a>
<a href="/reference/650.html">FI </a>
<a href="/reference/680.html">FOR </a>
<a href="/reference/651.html">FUNC </a>
<a href="/reference/681.html">GOSUB </a>
<a href="/reference/682.html">GOTO </a>
<a href="/reference/683.html">IF </a>
<a href="/reference/638.html">IFF </a>
<a href="/reference/666.html">IMP </a>
<a href="/reference/667.html">IN </a>
<a href="/reference/684.html">LABEL </a>
<a href="/reference/685.html">LET </a>
<a href="/reference/668.html">LIKE </a>
<a href="/reference/653.html">LOCAL </a>
<a href="/reference/1496.html">LSHIFT </a>
<a href="/reference/669.html">MDL </a>
<a href="/reference/670.html">MOD </a>
<a href="/reference/671.html">NAND </a>
<a href="/reference/654.html">NEXT </a>
<a href="/reference/672.html">NOR </a>
<a href="/reference/673.html">NOT </a>
<a href="/reference/686.html">ON </a>
<a href="/reference/674.html">OR </a>
<a href="/reference/688.html">REM </a>
<a href="/reference/689.html">REPEAT </a>
<a href="/reference/690.html">RETURN </a>
<a href="/reference/1497.html">RSHIFT </a>
<a href="/reference/655.html">SELECT </a>
<a href="/reference/1421.html">STEP </a>
<a href="/reference/656.html">STOP </a>
<a href="/reference/657.html">SUB </a>
<a href="/reference/658.html">THEN </a>
<a href="/reference/1437.html">THROW </a>
<a href="/reference/1420.html">TO </a>
<a href="/reference/1455.html">TRUE </a>
<a href="/reference/1425.html">TRY </a>
<a href="/reference/660.html">UNTIL </a>
<a href="/reference/661.html">USE </a>
<a href="/reference/1423.html">USG </a>
<a href="/reference/1422.html">USING </a>
<a href="/reference/691.html">WEND </a>
<a href="/reference/692.html">WHILE </a>
<a href="/reference/675.html">XNOR </a>
<a href="/reference/676.html">XOR </a>
</div>
</div>
</div>
<div class="pagefooter">
This page was last edited on Wed, 6 Sep 2023 18:17:39 +0200
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>