# catch

The operation belongs to the family of procedure-based communication operations. It is used to handle exceptions from a previously called procedure.

- The operation can be used on connected procedure-based (or mixed) ports.
- In case of multiple connections the operation may be restricted to one communication partner.
- Timeout constitutes a special case of exception.

Related keywords:

- address
- create
- from
- modifies
- sender
- signature
- system
- value

### port_reference.catch [ (signature_reference, template_instance ) ] [ from address_reference ] [ -> assignment_part ];

- port_reference points out the port where the exception is raised.

  - the keywords any port may be used to indicate that exceptions will be accepted at any port (see the example 4).

- The catch keyword introduces the exception capture.

- signature_reference points out the signature where the exception is defined

- template_instance may be one of the following (when omitted, any valid exception will be caught):

  - in-line signature template (see the example1);
  - a receiving template (see the example 2);
  - a modified template (see the example 3);

TITAN specific restriction compared to the standard:

- modified template is not implemented. When encountered in the TTCN-3 program, an error message will be generated.

- The optional from keyword is used when a port is connected to several entities and restriction to one communication partner is required.

- address_reference is one of the following:

  - a component reference (cf. create) or the keyword system, in case of one-to-many connections.

  - an address reference (cf. address) , when there are several entities within the system under test.

- assignment_part is one or both of the following:

  - the sender keyword followed by a variable of address or component type to store the address of the sender (see the example 2).
  - the value keyword followed by a variable of the appropriate type to store the exception value (see the example 3).

Example 1: in-line signature template

signature S_MyProcedure (inout integer pl_MyPar91) exception (integer, float);
MujPort_PCO.catch(S_MyProcedure, integer:14 .. 143) from system;

The signature S_MyProcedure is defined in the first line. It has one parameter (pl_MyPar91, pl_MyPar2 and pl_MyPar3). In the second line, an exception is caught at the port MujPort_PCO. The port is connected to several components, but communication is restricted to one component, here to the test system interface. Exceptions with the integer code between 14 and 143 are caught.

Example 2: signature template and address redirect

template IntegerFloatRecord tr_ExTemplate := {
field1 := 1 .. 6,
field2 := 0.0 .. infinity
}

MujPort_PCO.catch (S_MyProcedure, tr_ExTemplate) -> sender v_address;

The parameterized template (tr_ExTemplate) catches exceptions where the integer parameter lies between one and six, and the floating point value parameter greater than zero. The address of the component raising the exception is stored in the variable v_address.

Example 3: modified signature template and value redirect

MujPort_PCO.catch (modifies tr_ExTemplate := {field1 := 6}) -> value v_Exc;

The template defined in example 2 is modified. The response is now accepted when the integer parameter equals six. The returned exception value is stored in the variable v_Exc.

Example 4: receive on any port

any port.catch (tr_ExTemplate);

The exception matching the template tr_ExTemplate will be accepted on any port.

Example 5: Accepting any exception

MujPort_PCO.catch;

Removes the top exception from MujPort_PCO.

Example 6: Catching a timeout

MujPort_PCO.catch(timeout);

The exception caused by the timeout at the port MujPort_PCO is caught.

BNF definition of catch