Implementing Try / Catch / Finally
The Try
/ Catch
/ Finally
syntax has been around in languages like C# .NET for a very long time. Unfortunately, it has never made it into C/AL. This recipe will show you how to implement this type of control structure so that you can display error messages and still have your code continue to execute.
How to do it...
In Visual Studio create a new Class Library Project.
Add a file named
ITryCatchFinally.cs
with the following code:using System.Runtime.InteropServices; namespace TryCatchFinally { [ComVisible(false)] public delegate void OnTry(); [ComVisible(false)] public delegate void OnCatch(string errMessage); [ComVisible(false)] public delegate void OnFinally(); [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] [ComVisible(true)] public interface ITryCatchFinally { event OnTry NAVTry; event OnCatch NAVCatch; event OnFinally NAVFinally; void Execute(); } }
Add a file named
ITryCatchFinallyEvents.cs
with the following code:using System.Runtime.InteropServices...