All .NET UDFs created by FCell are automatically wrapped in try ... catch section. If exception is thrown in the UDF, the function will return #VALUE in Excel.

Sometimes you need more information about the underlying exception. To address this issue FCell exposes an event UdfErrorHandler.OnError

The error event is an F# IEvent<CallInfo*Exception>, where CallInfo is defined as:

F# Copy imageCopy
type XlRangeSize =
        RowCount : int
        ColCount : int

 type CallInfo =
        TypeName : string // type in which the UDF was defined
        MethodName : string // method which defines the UDF
        Args : XlData[] // arguments passed to the UDF
        CallerName : string option //ignore
        CallerSize : XlRangeSize //1x1 for single cell, rows x cols for Excel array formula
        CallerA1Ref : string //fully qualified A1 style reference to the range or cell which called the UDF

CallInfo allows you to trace each UDF error back to the Excel range where it was called.

The second component in the event is the actual exception that was thrown in the UDF

Each UDF error is automatically logged by log4net, using FCell config file located in %UserLocalAppDataFolder%\Statfactory\FCell\FCell.ManagedXll.dll.config

You can also subscribe your own handler to the OnError event, e.g. create a UDF which shows the error message every time there is a new error, e.g.:

F# Copy imageCopy
open FCell.ManagedXll
let lastErrorMsg() = UdfErrorHandler.OnError |> (fun (callInfo, ex) -> ex.Message)

When used in Excel, lastErrorMsg will update and show the error message every time a UDF throws an error.