{"name":"Exception handling","title":"Exception handling","type":"topic","url":"https://community.bistudio.com/wiki/Exception_handling","revid":377910,"updated":"2026-01-07T16:15:07Z","aliases":[],"markdown":"Armed Assault v1.00\n\nArmed Assault introduced exception handling through the try, catch and throw scripting commands, allowing scripts to create and react to exceptions.\n\nStandard structure:\n\n```sqf\ntry        // code block that can throw exception\n{\n    if (_name == \"\") then { throw \"no name\"; };    // this exits the try block and enters the catch block below\n    if (_name == \"\") throw \"no name\";            // since Arma 3 v1.54\n\n    titleText [format [\"Good morning, Captain %1.\", _name], \"PLAIN DOWN\"];\n}\ncatch    // code block that processes an exception\n{\n    if (_exception == \"no name\") then\n    {\n        hint \"Name was not entered\";\n        titleText [\"Good morning, anonymous Captain.\", \"PLAIN DOWN\"];\n    };\n};\n```\n\n> [!IMPORTANT]\n> Real Virtuality scripting commands do **not** create SQF exceptions by themselves if they encounter an illegal situation,\n>\n> they throw a ***compilation*** exception that cannot be caught by this try-catch structure explained here.\n>\n> The following would therefore **not** create a catchable exception:\n>\n> ```sqf\n> _divider = 0;\n> try        { a = 1 / _divider; }            // SQF error happens here already\n> catch    { hint \"illegal operation\"; };    // useless\n> ```\n>\n> The proper way:\n>\n> ```sqf\n> _divider = 0;\n> try        { if (_divider == 0) then { throw \"div0\"; }; a = 1 / _divider; }\n> catch    { hint \"illegal operation\"; };\n> ```","sections":[{"heading":null,"level":1,"markdown":"Armed Assault v1.00\n\nArmed Assault introduced exception handling through the try, catch and throw scripting commands, allowing scripts to create and react to exceptions.\n\nStandard structure:\n\n```sqf\ntry        // code block that can throw exception\n{\n    if (_name == \"\") then { throw \"no name\"; };    // this exits the try block and enters the catch block below\n    if (_name == \"\") throw \"no name\";            // since Arma 3 v1.54\n\n    titleText [format [\"Good morning, Captain %1.\", _name], \"PLAIN DOWN\"];\n}\ncatch    // code block that processes an exception\n{\n    if (_exception == \"no name\") then\n    {\n        hint \"Name was not entered\";\n        titleText [\"Good morning, anonymous Captain.\", \"PLAIN DOWN\"];\n    };\n};\n```\n\n> [!IMPORTANT]\n> Real Virtuality scripting commands do **not** create SQF exceptions by themselves if they encounter an illegal situation,\n>\n> they throw a ***compilation*** exception that cannot be caught by this try-catch structure explained here.\n>\n> The following would therefore **not** create a catchable exception:\n>\n> ```sqf\n> _divider = 0;\n> try        { a = 1 / _divider; }            // SQF error happens here already\n> catch    { hint \"illegal operation\"; };    // useless\n> ```\n>\n> The proper way:\n>\n> ```sqf\n> _divider = 0;\n> try        { if (_divider == 0) then { throw \"div0\"; }; a = 1 / _divider; }\n> catch    { hint \"illegal operation\"; };\n> ```"}],"categories":["Introduced with Armed Assault version 1.00","Scripting Topics"],"groups":["Scripting"]}