The TargetSite Property
The System.Exception.TargetSite property allows you to determine various details about the
method that threw a given exception. As shown in the previous Main() method, printing the value of
TargetSite will display the return value, name, and parameters of the method that threw the excep-
tion. However, TargetSite does not simply return a vanilla-flavored string, but a strongly typed
System.Reflection.MethodBase object. This type can be used to gather numerous details regarding
the offending method as well as the class that defines the offending method. To illustrate, assume
the previous catch logic has been updated as follows:
static void Main(string[] args)
{
...
Do'stlaringiz bilan baham: |