- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtrycatch.html
95 lines (95 loc) · 4.42 KB
/
trycatch.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
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="utf-8">
<metahttp-equiv="X-UA-Compatible" content="IE=edge">
<metaname="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | trycatch</title>
<metaname="description" content="SmallBASIC | One more basic">
<linkrel="canonical" href="/trycatch.html">
<linkrel="keywords" href="trycatch">
<linkrel="stylesheet" href="/css/style.css">
<linkrel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<scriptsrc="/clipboard.js"></script>
</head>
<body>
<buttononclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<scriptsrc="/backtotop.js"></script>
<divclass="wrapAll clearfix">
<navclass="navigation">
<divclass="logo">
<ahref="/"><imgsrc='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<divclass="navlinks">
<ahref="/pages/download.html">Download</a>
<ahref="/pages/news.html">News</a>
<ahref="/pages/community.html">Community</a>
<aclass='active' href="/pages/articles.html">Resources</a>
<ahref="/pages/reference.html">Language Reference</a>
<ahref="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<divclass="mainsection">
<divclass="tabs clearfix">
<divclass="tabsRight">
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/pages/trycatch.markdown">Edit</a>
<atarget="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/pages/trycatch.markdown">History</a>
</div>
</div>
<divclass="article">
<h1id="trycatch">Try/Catch</h1>
<blockquote>
<p>TRY/CATCH is used to trap errors allowing a program to recover
without having to be restarted.</p>
</blockquote>
<p><strong>TRY</strong></p>
<p>The TRY statement introduces a TRY/CATCH block.</p>
<p><strong>CATCH [var | expr]</strong></p>
<p>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.</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.</p>
<p>When using the expression mode, you can supply a succession of CATCH
statements to handle various error messages separately.</p>
<p><strong>END TRY</strong></p>
<p>The <strong>END TRY</strong> statement marks the end of a TRY/CATCH
block.</p>
<p><strong>THROW</strong></p>
<p>The THROW command (previously known as <strong>RTE</strong>) is used
to initiate a catch-able error. If there is no surrounding TRY/CATCH
block, THROW can be used to abort the program.</p>
<p><strong>Example</strong></p>
<divclass="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><codeclass="sourceCode smallbasic"><spanid="cb1-1"><ahref="#cb1-1" aria-hidden="true" tabindex="-1"></a><spanclass="kw">try</span></span>
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a><spanclass="fu">open</span><spanclass="st">"com2000:"</span><spanclass="kw">AS</span> #<spanclass="dv">1</span></span>
<spanid="cb1-3"><ahref="#cb1-3" aria-hidden="true" tabindex="-1"></a><spanclass="kw">catch</span> err</span>
<spanid="cb1-4"><ahref="#cb1-4" aria-hidden="true" tabindex="-1"></a> ? <spanclass="st">"in catch: open failed"</span>;err</span>
<spanid="cb1-5"><ahref="#cb1-5" aria-hidden="true" tabindex="-1"></a><spanclass="kw">end try</span></span></code></pre></div>
<p><strong>Try/Catch in other languages</strong></p>
<ul>
<li><a
href="http://www.cplusplus.com/doc/tutorial/exceptions">C++</a></li>
<li><a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">Javascript</a></li>
<li><a
href="http://msdn.microsoft.com/en-AU/library/fk6t46tz.aspx">Visual
Basic</a></li>
</ul>
<p><strong>History</strong></p>
<p>The TRY/CATCH mechanism was introduced in version 0.11.15.</p>
</div>
<divclass="pagefooter">
This page was last edited on Sat, 9 Sep 2023 22:31:16 +0200
|
<ahref="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<ahref="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>