Exception handling

From Bohemia Interactive Community
Revision as of 01:14, 22 July 2022 by Lou Montana (talk | contribs) (Some wiki formatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In Armed Assault exception handling is an implemented system of special scripting commands (try, catch and throw), which allows your scripts to create and to react to exceptions.

Standard construction is:

Copy
try { // code block that can throw exception if (_name == "") then { throw "no name"; } else { titleText [format ["Good morning, Captain %1.", _name], "PLAIN DOWN"]; sleep 1; titleText [_name, "PLAIN DOWN"]; }; } catch { // code block that processes an exception if (_exception == "no name") then { hint "Name was not entered"; titleText ["And the name isn't", "PLAIN DOWN"]; }; };

Arma scripting commands do not create SQF exceptions by themselves if they encounter an illegal situation, they throw a compilation exception (i.e. the here-described exception handling cannot be used for error trapping).

The following would therefore not create a catchable exception:

Copy
try { a = 1 / 0; // SQF error happens here already } catch { hint "illegal operation"; // useless };