try: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (try controls the flow)
(added better short example, link to long description)
Line 21: Line 21:
'''Description:'''
'''Description:'''


Defines try-catch structure.
Defines a try-catch structure.


This is structured exception block.
This sets up an [[Exception handling|exception handling]] block.


Any thrown exception in '''try''' block is caught in [[catch]] block.
Any thrown exception in a '''try''' block is caught in a [[catch]] block.


The structured exception block has following format:
'''Example:'''


 
'''try''' {
'''try''' //begin of try-catch block { //block, that can throw exception }
  if (_name == "") then {
 
    [[throw]] "No Name"
[[catch]] { //block, that processes an exception}.
  }
 
}
Exception is described in _exception variable.
 
[[catch]] {
  if (_exception == "No Name") then {
    ....
  }
}

Revision as of 06:04, 23 July 2006


try code


Operand types:

code: Code

Type of returned value:

Nothing

Compatibility:

Version 2.60 required.

Description:

Defines a try-catch structure.

This sets up an exception handling block.

Any thrown exception in a try block is caught in a catch block.

Example:

try {
  if (_name == "") then { 
    throw "No Name"
  }
}
 
catch {
  if (_exception == "No Name") then {
    ....
  }
}