13.07.2015 Views

Macro Guide - Esker

Macro Guide - Esker

Macro Guide - Esker

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Error Handling (topic)For user-defined errors, the Err.Source property can be set to any valid string expression indicatingthe source of the error. If the Err.Source property is not explicitly set for user-defined errors, the valueis the name of the macro in which the error was generated.ExampleFunction InputInteger(Prompt,Optional Title,Optional Def)On Error Resume NextDim x As Integerx = InputBox(Prompt,Title,Def)If Err.Number ThenErr.Source = "InputInteger"Err.Description = "Integer value expected"Err.Raise 3000End IfInputInteger = xEnd FunctionSub MainOn Error Resume Nextx = InputInteger("Enter a number:")If Err.Number Then Session.Echo Err.Source & ":" & Err.DescriptionEnd SubSee Also <strong>Macro</strong> Control and Compilation on page 6Error Handling (topic)The macro language supports nested error handlers. When an error occurs within a subroutine, thecompiler checks for an On Error handler within the currently executing subroutine or function. Anerror handler is defined as follows:Sub foo()On Error Goto catch'Do something here.Exit Subcatch:'Handle error here.End SubError handlers have a life local to the procedure in which they are defined. The error is reset when anyof the following conditions occurs:• An On Error or Resume statement is encountered.• When Err.Number is set to -1.• When the Err.Clear method is called.• When an Exit Sub, Exit Function, End Function, End Sub is encountered.Cascading ErrorsIf a runtime error occurs and no On Error handler is defined within the currently executing procedure,then control returns to the calling procedure and the error handler there runs. This process repeats until249

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!