How to extract the first two lines of Exception

Hi All,

I want to extract the first two lines of Business Exception. The Business exception message may vary but I want to extract just the first two lines of Business exception from the long message when ever there is any Exception .

In this scenario I want to extract till Sales Order but at other times the business exception message may vary . So I just want to extract the first two lines of message what ever the business exception scenario may be

Below are the two Business Exception message and I want to extract just the two lines from the long message

UiPath.Core.BusinessRuleException: 0063f000004MKCmAAO has Null Signature Date
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
β€” End of stack trace from previous location where exception was thrown β€”
at UiPath.UIAutomationNext.Activities.NApplicationCard.OnFault(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)

UiPath.Core.BusinessRuleException: 0063f000004MKCmAAO has multiple Sales Order
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
β€” End of stack trace from previous location where exception was thrown β€”
at UiPath.UIAutomationNext.Activities.NApplicationCard.OnFault(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

@marina.dutta

Please fine the below expression

(?<=\n)UiPath.*\s+.*

or else use

System.Text.RegularExpression.Regex.Matches(Your String Input,"((?<=\n)UiPath.*\s+.*)")
(?<=\n)\w+\..*\s+.*

or else use

System.Text.RegularExpression.Regex.Matches(Your String Input,"((?<=\n)\w+\..*\s+.*)")

Regards

Hi @marina.dutta

Please try this

(^.+?[\r\n]+.+?[\r\n]+)

Hi @marina.dutta ,

Could you let us know how are you currently adding the Business Exception Message ?

For Business Exceptions, since it is already known, we would use just the Message :

BusinessExceptionVar.Message

@supermanPunch

I am getting the Entire Business Exception message in Status Email. Something like this .When I am doing BusinessException.Message. I want a shorter Message in my status Email hence want to filter it out. I am creating Data Row in Set Transaction Status for each Business, System Exception and Success sates . When it Captures Business Exception Message , It captures the entire message.


pleas share with us full statement from the ArrayRow

Hi @marina.dutta

Check the below regex expression to extract the first two lines of business exception.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,β€œ(^UiPath.*\n.*)”)

Hope it helps!!

@mkankatala

Getting some error.

You are storing the data in a string variable.
Change the variable type to IEnumerable of Matches.

Follow the below steps to change the datatype to matches
=> Open variables panel and for your variable click on the Variable type it shows the dropdown, then select the browse for types
=> Search for the System.Collections.Generic.IEnumerable in the seach bar
=> Then select the dropdown at top and select one more browse for types.
=> Search for the Matches and hit on Okay for the opened two windows.

Then the variable type changed to the IEnumerable of matches, then the error will gone.

Hope you understand!!

@marina.dutta

(?<=\n)\w+\..*\s+.*

or else use

System.Text.RegularExpression.Regex.Matches(Your String Input,"((?<=\n)\w+\..*\s+.*)")

Regards

@marina.dutta

Please fine the below expression

(?<=\n)UiPath.*\s+.*

or else use

System.Text.RegularExpression.Regex.Matches(Your String Input,"((?<=\n)UiPath.*\s+.*)")

Hope it works!!

@mkankatala

You have selected the matches another one
You have to select the match under the System.Text.RegularExpressions
Find the below screenshot

Hope you understand

the return of Regex.Matches is of DataType: MatchCollection
As the pattern is intended to catch 1 match it is not needed to look for multiple matches

so we would use:

System.Text.RegularExpressions.Regex.Match(TextString, PatternString).Value 

and will get back a String

However, we would also recommend checking that not the stacktrace property is mismatched with the message property

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.