Try OpenEdge Now
skip to main content
GUI for .NET Programming
Accessing and Managing .NET Classes from ABL : Handling .NET exceptions : Using properties and methods on .NET Exception objects
 

Using properties and methods on .NET Exception objects

System.Exception supports a common set of Microsoft .NET properties and methods that are inherited by all .NET Exception objects. In addition, each derived Exception object can have its own unique set of properties and methods. In ABL, you can access all of these Microsoft properties and methods.
In addition, with implementation of the Progress.Lang.Error interface provided by OpenEdge, you can also access .NET Exception objects in a manner generally consistent with accessing ABL error objects, including Progress.Lang.ProError and all of its subclasses. This is particularly true of accessing .NET exception messages.
.NET Exception objects all support a Message property that returns the human-readable message for the exception. In addition, each Exception object supports an InnerException property that can reference another Exception object that has directly lead to throwing the current Exception object. Thus, this InnerException property can reference an exception chain with any number of Exception objects, each of which returns a message from its own Message property. Using the OpenEdge-extended GetMessage( ) method, you can access every message from this entire chain of Exception objects without having to walk the InnerException object chain.
The following table shows a summary of all the OpenEdge-extended properties and methods, and how they work with .NET Exception objects.
Property or method
Description
CallStack property
Lists the ABL procedure and class call stack at the time a .NET method was called or a .NET data member or property was accessed that caused the exception.
Note: The .NET StackTrace property is entirely different and lists only the stack of .NET calls within the CLR where the .NET exception originated.
GetMessage ( n ) method
Returns the nth message in a message list. For a .NET Exception object, each message in addition to the first one in the list represents a separate inner exception message.
Also, each such message indicates both the type name of the Exception object that generated the message and the text of its Message property. For example, if a System.ArgumentOutOfRangeException object is caught with its Message property set to "Index 2 is out of range", this method returns a corresponding message with the following value:
"System.ArgumentOutOfRangeException: Index 2 is out of range"
GetMessageNum ( n ) method
Non-functional (always returns 0).
NumMessages property
Returns the number of messages listed for the Exception object, including all of its inner exceptions.
Severity property
Non-functional (always returns 0).
As noted at the start of this section, different types of .NET Exception objects can have their own unique set of properties and methods. For example, the FileNotFoundException, shown in the previous code fragment, has a FileName property that identifies the name of the file that cannot be found. You can only access such custom properties and methods directly on the .NET Exception object itself, and the information they provide is not available using OpenEdge-extended properties or methods. So, for an inner exception, you need to walk the exception chain to locate a given Exception object in order to access its custom properties and methods.