Exception handling: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(moving discussions to talk page)
m (Added missing ";" after catch blocks. (2 times))
Line 19: Line 19:
         TitleText ["And the name isn't", "PLAIN DOWN"]
         TitleText ["And the name isn't", "PLAIN DOWN"]
     }
     }
  }
  };


'''Note:''' ArmA scripting commands do '''not''' create an exception by themselves if they encounter an illegal situation (i.e. you can't use the here described exception handling for error trapping.)
'''Note:''' ArmA scripting commands do '''not''' create an exception by themselves if they encounter an illegal situation (i.e. you can't use the here described exception handling for error trapping.)


The following would therefore '''not''' create a catchable exception:  
The following would therefore '''not''' create a catchable exception:  
<code>try {a=1/0;} catch {hint "illegal operation";}</code>
<code>try {a=1/0;} catch {hint "illegal operation";};</code>




[[Category: Scripting Topics|Exception Handling]]
[[Category: Scripting Topics|Exception Handling]]

Revision as of 15:29, 29 September 2007

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:

try {
    //block, that can throw exception
    if (_name == "") then {
        throw "no name"
    } else {
        TitleText [format["Good morning, Captain %1.", _name], "PLAIN DOWN"]
        ~1
        TitleText [_name, "PLAIN DOWN"]
    }
}
catch { //block, that processes an exception if (_exception == "no name") then { echo "Name wasn't entred" TitleText ["And the name isn't", "PLAIN DOWN"] } };

Note: ArmA scripting commands do not create an exception by themselves if they encounter an illegal situation (i.e. you can't use the here described exception handling for error trapping.)

The following would therefore not create a catchable exception: try {a=1/0;} catch {hint "illegal operation";};