User Tools

Site Tools


try_arm_exception_handling_.htm
Navigation:  Clarion.Net (Clarion#) > Clarion# Language Extensions > Exception Handling >====== TRY-CATCH-FINALLY (exception handling block) ====== Previous pageReturn to chapter overviewNext page

NewCNet.jpg

TRY

statements that can cause an exception

CATCH

statements to handle exception

FINALLY

statements to cleanup after an exception

END

TRY Arm exception handling
statements any code that may produce an exception.
CATCH Trap an exception
statements Code to perform the appropriate recovery or alert the user. This code is only executed if an exception occurs. You may have multiple CATCH blocks. At the end of each CATCH block you can either throw the same exception (See THROW statement), throw a different exception, or let the code fall out of the CATCH block.
FINALLY Clean up exception handling
statements Code in this block is always executed and can perform cleanup after an exception. The FINALLY block is optional.

blk2blue.jpg

TRY-CATCH-FINALLY is a code block used for exception handling.

If any exception occurs within the TRY block, the .Net runtime searches the CATCH blocks for an appropriate exception. If you have multiple CATCH blocks put the more specific exceptions at the top and the more generic exceptions last. The FINALLY block is always executed and can be used to do cleanup operations after an exception.

The TRY block must be followed by a CATCH or FINALLY. You can have a TRY block without a CATCH as long as you have the FINALLY block.

Examples:

CODE

TRY

 F()  !calling a function

 CATCH (Exception e)

  MESSAGE('Exception in code: ' & e.Message)

END

! CODE FOREACH ctrl in SELF.Controls  IF(ctrl Is TextBox)   IF(NOT ctrl.Tag&=null)    colnm&=ctrl.Tag    tab&=SELF.m_Row.Table    tp&=tab.Columns[colnm].DataType    val&=(ctrl TryAS TextBox).Text    IF1)  END See Also:** THROW

1)
ctrl TryAs TextBox).Modified)     SELF.Modf=true     TRY      SELF.m_Row[colnm]:=Convert.ChangeType(val,tp)     CATCH Exception ex      MESSAGE('Invalid value in field: ' &amp; colnm)      SELF.DialogResult=DialogResult.None      RETURN     END    END   END  END END CODE TRY  F()  !calling a function CATCH (Exception e)   MESSAGE('Exception in code: ' &amp; e.Message) FINALLY   !Any cleanup code here END CheckErr    PROCEDURE CODE  IF(ERRORCODE()<;>0)   THROW NEW DataException('ERROR: ' &amp; ERROR(
try_arm_exception_handling_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1