{"name":"throw","operator":null,"title":"throw","type":"command","url":"https://community.bistudio.com/wiki/throw","revid":377911,"updated":"2026-01-07T16:33:15Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Throws an exception. The exception is processed by first catch block. This command will terminate further execution of the code.\n\n> [!IMPORTANT]\n> Avoid using alternative shorthand syntax if you are planning on preparing your exception information dynamically, as it will have to be generated first regardless of the condition of the if statement before it, as shown in #Example 3.","syntaxes":[{"syntax":"throw exception","since":null,"effect":null,"exec":null,"params":[{"name":"exception","type":"Anything","optional":false,"default":null,"description":"value that is put into the `_exception` variable inside catch block","types":["Anything"],"since":null,"text":"exception: Anything - value that is put into the `_exception` variable inside catch block"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"exception","types":["Anything"]}},{"syntax":"ifType throw exception","since":"arma3 1.54","effect":null,"exec":null,"params":[{"name":"ifType","type":"If Type","optional":false,"default":null,"description":"if the condition returns true, *exception* is thrown","types":["If Type"],"since":null,"text":"ifType: If Type - if the condition returns true, *exception* is thrown"},{"name":"exception","type":"Anything","optional":false,"default":null,"description":"value that is put into the `_exception` variable inside catch block","types":["Anything"],"since":null,"text":"exception: Anything - value that is put into the `_exception` variable inside catch block"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"ifType","types":["If Type"]},"right":{"text":"exception","types":["Anything"]}}],"examples":[{"text":"```sqf\ntry { throw \"invalid argument\" } catch { hint str _exception };\n```","code":["try { throw \"invalid argument\" } catch { hint str _exception };"]},{"text":"```sqf\n123 try { if (_this != 123) throw \"invalid argument\" } catch { hint str _exception };\n```","code":["123 try { if (_this != 123) throw \"invalid argument\" } catch { hint str _exception };"]},{"text":"The correct usage of shorthand alt syntax:\n\n```sqf\ntry\n{\n    if (a > b)\n        throw \"Error: some error\";                // OK - the command argument is static\n}\ncatch\n{\n    hint str _exception;\n};\n```\n\n```sqf\ntry\n{\n    if (a > b)\n        throw (call _someFunc);                    // NOT OK - the command argument is dynamic\n        // _someFunc is called first to get the value regardless of (a > b) outcome\n}\ncatch\n{\n    hint str _exception;\n};\n```\n\n```sqf\ntry\n{\n    if (a > b) then { throw (call _someFunc) };    // OK - the command argument is dynamic\n    // _someFunc is only called when (a > b) is true\n}\ncatch\n{\n    hint str _exception;\n};\n```","code":["try\n{\n\tif (a > b)\n\t\tthrow \"Error: some error\";\t\t\t\t// OK - the command argument is static\n}\ncatch\n{\n\thint str _exception;\n};","try\n{\n\tif (a > b)\n\t\tthrow (call _someFunc);\t\t\t\t\t// NOT OK - the command argument is dynamic\n\t\t// _someFunc is called first to get the value regardless of (a > b) outcome\n}\ncatch\n{\n\thint str _exception;\n};","try\n{\n\tif (a > b) then { throw (call _someFunc) };\t// OK - the command argument is dynamic\n\t// _someFunc is only called when (a > b) is true\n}\ncatch\n{\n\thint str _exception;\n};"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["Exception handling","try","catch"],"notes":[],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Armed Assault version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}