Get project name - state name - workflow name from inbuilt methods

Some background: I’m trying to build an exception library [with an exception activity] which gets called in the catch of a try-catch scenario. This activity will be used in multiple RPA projects This exception activity will take all information it can get (exception.source, exception.message, exception.gettype). these above values are easy to get. I’m also interested in logging where the exception took place. like the project-reframework state-workflow level hierarchy and append it to my final exception message which will contain all these details in a csv.

Is there any inbuilt method (.Net) which can help me get these values? I will be calling these in the library activity and that activity will be used in projects.

Hope that makes the question easy to understand.

@ClaytonM @vvaidya would be great if you guys can suggest something

I guess I don’t understand what you mean by “where the exception took place”. Do you have an example?

exception.Source should already give you the activity(s) that caused the exception - so make sure you are descriptive in the activity names… You can also provide details in the message if it is a custom exception like when Credentials are invalid, etc. You might also need to use the source and message as arguments rather than the entire exception, in case you need to customize those values in your logging.

Thanks for getting back to me. Let me share an example.

There is a project called alpha. inside the process transaction state of alpha, there is a workflow called beta.xaml
inside beta.xaml, there is a try catch. the try has 5 activities in a sequence (open a window, click on a selector, print a value and so on). The catch has an exception library whcih will get triggered if there is an exception triggered from the ‘click on a selector’ activity if the selector is invalid.

Right now, my exception library only logs exception.source, exception.message, exception.gettype.
I want the library to also give me the hierarchy of the exception. Eg. alpha - process - beta - click on a selector. Currently, I can get the last one, but no the other three. Are there any built in methods / activities that can give me the same?

Please let me know if you any questions regarding the same.

Appreciate the help

As of now, the best way to get that hierarchy is like this:

Use Try/Catches around Invokes, and handle the error from outside the workflow. If you need the inner workflow to have special error handling, then use the Throw activity with a custom message.

When, you use the Invoke and an error occurs, it will show the invoked workflow and activity that error’d. Like, “Invoke beta.xaml: Click Selector: Message”

If you need the Process noted in the message, then you need to customize that when you send to your Library to Log the exception, because the exception does not include that part. And, the same for the project name.

Hopefully that helps.

Thank you for the reply.

I understand most of it.

This part - ‘then you need to customize that when you send to your Library to Log the exception, because the exception does not include that part. And, the same for the project name.’

I still don’t understand. when you say customize, any ideas or starting points for me to look at? Do you know any libraries or packages that have the functionality for me to get the project and state variables?
I’d have to look at project.json and read that to get the project name and then pass it in the library, but its cumbersome process and I’m hoping there is an easier way out.

Best,
Jash

Actually, you can get the project name from the json. To do this (probably at some point during the Init phase), use Read Text file of “project.json”, then use Deserialize JSON and output that to a jsonObject variable. With that variable, you can reference or store the project name to your config dictionary. For example, Assign config("ProcessName") = jsonObj("name").ToString

The other thing you want is the state name, well I believe there is no .net to reference that value, so you just need to hardcode it. So, depending on what state you are in, you just add either “Init” or “Process” to the message.

In order to allow such customization, your Library will need to include arguments that let you customize the message in some way…
For example,

Let me first suggest you use a Format for your Log Message. You then can use String.Format() to easily place the values in your message.

Let’s say you store this format in the config (which comes from the Excel file), so

config("ApplicationExceptionMessageFormat") = "[APPLICATION EXCEPTION] {0} > {1} > {2} > {3}"

Then, your Library could have an Argument for LogMessage, where you use this message format and replace the values you want for items 0 - 3
Like,

Argument(s)
LogMessage = String.Format(config("ApplicationExceptionMessageFormat").ToString, config("ProcessName").ToString, "Process State", exception.Source, exception.Message)

Then, since you are sending the full message to your Library, you can send it anything you want to Log. However, there are probably many approaches to this as well.

Hope that makes sense

Regards.

Also, if you are wanting the message to be more global like used by all projects, then you’ll just need to include the Process name and State level as arguments:

Argument(s)
in_Exception = exception
in_ProcessName = config("ProcessName")
in_StateLevel = "Process State"

Then, inside your library workflow you can pretty much do the same thing with String.Format() if you would like or just store it directly into the variable, and have that format string as part of that Library rather than of the project.

messageFormat = "["+in_Exception.GetType+"] "+in_ProcessName+" > "+in_StateLevel+" > "+in_Exception.Source+" > "+in_Exception.Message

Regards.

@ClaytonM Thank you. Appreciate the detailed response. I did end up doing the same thing you mentioned and it works just fine.

Thanks again. Best wishes.

-Jash