OpenTTCN/Training/TTCN-3 Basics/Exercises/3.3

From OpenTTCN

Jump to: navigation, search

Exercise 3.3: Using error handlers to streamline code

Goal: In this exercise we are learning how to use error handlers (defaults) to streamline code. Common error situations can be handled in a default that is executed in the end of each explicitly specified alternative.

Step 1: Using error handlers to streamline code

The alternatives we have been specifying are getting longer and longer. Usually the first alternative we have in our alt statements is the expected valid input. Besides that we might specify the expected error next and then continue alternatives for receive any and timeout supervision. The test case becomes complex and unreadable when alternatives are getting longer. To avoid this we can group alternatives for common error situations to error handlers that are called defaults. The defaults are specified by writing an altstep and activating this altstep at correct location.

Step 2: Write error handler for TC_receive

Instructions: Enhance your "TC_receive" test case and move the receive any and timeout alternatives to new alstep that you call "AS_generic_default". Discuss with your instructor how the used timer can be accessed? It seems that we know how to prepare to the use of defaults beforehand.

Step 3: Activate the error handler

Instructions: Enhance your "TC_receive" test case and activate the "AS_generic_default" in the beginning of the test case. Discuss with your instructor about the need to save the default reference returned by the activate statement. This is related to the needs of your test case, but it is also related to larger issue of TTCN-3 Core Language versions/editions.

Step 4: Default processing with TTCN-3 Edition 2 and Edition 3

Your instructor explains the differences with default processing in TTCN-3 Edition 2 and Edition 3.

Summary

Jätte bra! You have just completed your third TTCN-3 exercise of today. During this exercise you learned how to define error handlers and how to activate them to handle common error situations. You are now ready to proceed to the next exercise to learn how to use module parameters.

<< Previous   Next >>

Views
Personal tools