TryFunction property has been introduced to C/AL to handle exceptions thrown by .NET objects. It allows NAV application developers to catch exceptions and handle them the way the
try...catch statement would in C#.
The following example explains how to declare a try function and catch exceptions from .NET objects.
TryFunctionattribute at all, let's create a codeunit with a function that will fail and throw a .NET exception. Let's call the
GetDataFromRemoteSourcefunction and suppose it is intended to load data from some web resource:
HttpWebRequest := HttpWebRequest.Create('http://unknown'); HttpWebResponse := HttpWebRequest.GetResponse;