KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Error Trapping Using a Case Statement
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: April 21, 2000

Here is an easy way of trapping for errors when executing a number of steps in a method. By separating the code into a set of case expressions, it is possible to progressively test the results. If a false value is returned at each point, then the next case expression will be evaluated. If a true value is returned at any point, then the rest of the case statement will be skipped.

In the example below, when method DoSomething is finished executing, it will return False and the next expression in the case statement will be evaluated. When the method TryAgain is executed, it will return True which causes 4D to execute any code included in the TryAgain segment (in this example there is none), but additional expressions appearing after TryAgain will not be evaluated and their code will not be executed.