Project

General

Profile

Exceptions in Scol » History » Version 1

iri, 09/25/2012 12:44 AM

1 1 iri
h1. Exceptions in Scol
2
3
*exceptions* are not yet explicitely supported.
4
5
However, you can use this method :
6
7
"*_testpakS*":http://www.scolring.org/files/doc_html/_testpakS.html is a Scol function. It loads a source string in the current environment without running and it returns nil if no error found or an explicit string message if an error occurs. But the program continue.
8
9
10
<pre>
11
let _testpakS <string_code> -> result in
12
if result == nil then	// no error
13
	_loadS <code>
14
else
15
	// to do something
16
// continue
17
</pre>
18
19
20
Something like that :
21
22
<pre>
23
proto divideX = fun [] I;;
24
25
fun main ()=
26
	_showconsole;
27
	
28
	srand time;
29
	let (((rand&255)*100)>>8)-50 -> x in	// randomized value (-50 +50)
30
	let strcatn "fun divideX () = 100 / " :: (itoa x) :: ";;" :: nil -> strCode in
31
	let _testpakS strCode -> res in
32
	if (nil == res) then	// it's ok
33
	(
34
		_loadS strCode;	// we load and run this part of code
35
		_fooId divideX;
36
	)		
37
	else	// divide by zero !
38
	(
39
		_fooS res;
40
		_fooId x;
41
		1;
42
	);
43
	0;;
44
</pre>
45
46
Depending on the context, you can also use the Scol functions "*_testpak*":http://www.scolring.org/files/doc_html/_testpak.html or "*_test_exist*":http://www.scolring.org/files/doc_html/_test_exist.html.
47
48
49
License : "CC-BY-SA-2.0":https://creativecommons.org/licenses/by-sa/2.0/
50
Tutorial by iri
51
Updated by /