Library Components: When throwing an error from inside activity the exception The exception.Source is non-descriptive

Some of our Re-usable components, that we have recently created a library for, involve throwing errors. For Example one is called CheckFileExists and will throw an error if the file path provided is invalid. We have had an issue with the Exception Source being non-Descriptive.
When throwing an error from inside custom-activity the exception source just says: System.Activities.
Is there anyway to fix this? Inside the re-usable components I have surrounded everything in a try-Catch and upon error assign the Exception-Source then rethrow. But the issue is now that the source doesn’t tell me exactly where in the main the Error came from.

Thanks!

1 Like

You shoud use the Throw activity like this:

Exception = New Exception(“This error came from my component”, ExceptionFromOriginalPlace)

That will not fix the issue. I am doing this:
Exception.Source = “Component Name”

But when it throws errors inside the Main.xaml it will only tell me what activity failed not the scope or location of activity. This is a problem because we could use a certain activity more than once through-out and not know which exact one threw the error.

If you’re using the “Throw” Activity, then I would suggest naming the Activity, I typically name it something like Throw - <.xaml_name> -- <location_description> and then for the exception by doing new System.Exception(<ERROR_DETAILS>). You can add any details you want, this is good if you’re throwing a SPECIFIC error, and you can then detail it’s location as well.

If this this in a try catch and you don’t know what the error will be, when you catch the error, you can do the following:
new System.Exception(exception.Message + " -- <ADDITIONAL_DETAILS>")

There’s a certain level of tedium that comes with creating really solid and dynamic error logging, but it’s all about consistency. It would be really great if we could have the Environment variables/methods expanded (or preferably a Global Variables/Methods, not Environment), being able to call a method like stringVar = Environment.GetActivityName() to get the current activity name would be awesome, but they seem to be leaving Environment variables alone for the time being.

i mean there is no way that it would tell you where it came from, you need to use the exception that is generated and pass it along as innerexception property…