Try Catch: What fields to log within Exception Object

What are the fields I should log in Log message for the complete info on the exception object for debugging later? (Just logging exception.Message is not helpful often.)

1 Like

Hi @RajeshSwarnkar

You can read this link for your reference.

cheers :smiley:

Happy learning :smiley:

2 Likes

Hello,

I am trying to log the below fields from System.Exception within the catch part of Try Catch activity. But I am not able to get the name of the activity from which the exception arises. This will be very bad in production. If I do not use the Try Catch, the studio shows the error popup showing exactly all the fields of the exception like :

Type of Exception. Exception Trace. Excpeption message, Exception causing activity.

I even tried to log below fields:

  • exception.Message: This gives exception message but not inner exception trace and name of the source

  • exception.StackTrace: This gives just trace. No name for the source activity name.

  • exception.Source: This is just returning System.Activities

  • exception.TargetSite: Void Execute(System.Activities.CodeActivityContext)

  • exception.GetType: System.Exception

  • exception.InnerException : null

  • exception.HResult : Null

  • exception.HelpLink

  • exception.GetBaseException

  • exception.InnerException

  • exception.ToString: No source

Can you please help me iterating through all the important fields of exception to have error message just like what we get in pop up from Studio?

@RajeshSwarnkar

Hi,

You should create your own exceptions to handle errors, since you are a Developer this is best practice, and for those you are not aware you can use to write exception to a string instead of writing exception.Message.

1 Like

Pardon, I can’t recall much of exception handling as of now. Would learn some on exception hierarchy and come back.

for those you are not aware you can use to write exception to a string instead of writing exception.Message.

Can you please show an example?

Sure,

Depending on what happened in the workflow Try Catch bahaviour differently:
image

For BusinessRuleExceptions it will just add information to Log file
For Application Exception it will retry this transaction item but first close all iExplore windows and run it from the beggining
For MissingMethodException it will add some additional information to the Log file
And I’m using exception to catch everything I didn’t predict while doing solution, unhandled exceptions. Once in the week I’m reading log file for unhandled exception and i’m trying to improve solution if there are any errors.

1 Like

Check this: Try Catch Printing Exception Source

Seems you need to invoke the workflow to be able to get the exception.Source inside it.

1 Like

Not Agree, we as a developers are able to create own exceptions to handle “something”, exception are not only the Errors in the code. Imagine that you are having try catch, inside there is sequence with some data validation, you got inforation from business that one field of data shouldn’t be an integer, it has to be a text. In that scenarion you could use IF statement and if value is not pure text, you can use Throw activity, to throw exception, you are able to give type and message. So you can create New BusinessException(“Value is not text”) and catch it under the Catch, and for this particular error your robot do something “extra” :wink:

That is good Idea. However, we should refrain using the exceptions for program flow ::wink:

1 Like