Try catch not catching anything!

Hi - I am working with Microsoft Edge, clicking through a website. Sometime the Ui I am selecting is not present and so to deal with it I have put it in a try catch with the catches being both System.Exception and UiPath.Core.SelectorNotFoundException (I have used both because neither are catching the exception).

I continue to get the error message:

Something went wrong with .
Activity Get Text ‘Overview’ (N Get Text) failed:

Could not find the user-interface (UI) element for this action. Possible solutions: • Ensure application is opened and the UI element is visible on the screen at execution time • Edit the Target of the UI activity and use Validation to debug the issue. • If needed, re-indicate the element as its properties might have changed • Use “Check state” activity to check the application state before executing the action • Increase the “Delay before” value to allow time to the application to render entirely and become responsive

You can find the activity by searching id (press Ctrl + J to jump to activity):
0102DE

I have put log messages in both catches and neither are being triggered.

Any advice on what is going wrong? I would attach the workflow here but it is confidential in nature and so I cannot share on a public forum.

Thanks in advance

Mark

Do you have continue on error set for the activity?

Ideally this will be caught by system.exception
In catch block

Is this GET TEXT activity placed inside the TRY Block of TRY CATCH activity
Or is it placed in catch or final block

If it’s in try block then it will be caught
But if it’s in catch block or final block then the activities inside then will throw error

Try catch should encompass the activity that might throw the exception. Verify that there are no nested Try-Catch blocks that might catch the exception before it reaches your intended Try-Catch.

@Mark007

Hi @postwick - it has been left as default (which I recall is False).

Thanks

Mark

Hi @Palaniyappan, the Get Text sits in the Try block and so as you say should have triggered the exception. What is odd is an activity sits before it in the Try block that should have triggered the exception first but didn’t.

Thanks

Mark

Well I think then u r running in debug mode
Run in normal mode
Click on drop down button in play button and click run project or run file

@Mark007

Hi @Palaniyappan - I am not running it from StudioX, I am running it from Assistant and so it is not in debug mode.

Thanks

Mark

Hmm can u share a screenshot of the sequence
@Mark007

@Palaniyappan I can’t share on a public forum. Would you be willing and able to do a quick teams call?

Hmm
I m worried that I won’t be able to join on call

Can u share a pseudo code
Like this
Names of activities in sequence

@Mark007

@Palaniyappan

Within the Try Catch:
TRY
Click button (should fail)
Log message (added for debugging) - log message prints
Keyboard Shortcut
Click button (set to continue on error - True otherwise would fail)
Get Text (fails and creates an error)
Log message (added for debugging) - log does not print

CATCHES
Exception
Log message for debugging - log does not print
SelectorNotFoundException
Log message for debugging - log does not print

FINALLY
Delay

Is that what you meant?

It’s worth noting the entire workflow runs fine when the buttons in the try catch are present in the Ui.

Thanks again

Mark

Try having only system.Exception alone and run once
Remove all continue on error make it as false

@Mark007

Hi @Palaniyappan - unfortunately it still failed.

Does the below help at all?

Thanks

Mark

1.1021 Try Clicking About (TryCatch)
Private = False
Try
1.956 Group (Sequence)
Private = False
Activities
1.1033 Click ‘About’ (NClick)
Activate = True
Click type = Single
Key modifiers = None
Mouse button = Left
Input mode = HardwareEvents
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
CV Text = About
CV Control type = Text
Strict selector =
Fuzzy selector =
Targeting methods = Selector
Private = False
1.992 Get Text From About (NGetText)
Text = About
Scraping method = Default
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
Anchor 1
Strict selector =
Fuzzy selector =
Targeting methods = Selector
CV Control type = None
CV Control type = None
Strict selector =
Fuzzy selector =
Targeting methods = Selector, FuzzySelector
Private = False
1.1023 Click Show more (NClick)
Activate = True
Click type = Single
Key modifiers = None
Mouse button = Left
Input mode = SameAsCard
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
CV Text = With over 20 years SAP recruitment experience and lived and worked in the UK and US…Show more
CV Control type = Text
Strict selector =
Fuzzy selector =
Targeting methods = Selector
Private = False
Catches
Catch (Catch)
ExceptionType = System.Exception
Action
1.921 Log Message (LogMessage)
LogLevel = UiPath.Core.Activities.LogLevel.Info
Message = About Section Isn’t Present and Exception Thrown
Private = False
Finally
1.1022 Group (Sequence)
Private = False
Activities
1.969 Delay (Delay)
Duration = New TimeSpan(0, 0, (New Random().Next(30, 60)))
Private = False
1.945 Go To URL (NGoToUrl)
URL = CurrentRow.ByField(Name Url)
Private = False
1.900 Set Variable Value (Assign)
To variable = CompanyInfo
Set value = string.Format(No Company Info)
Private = False
1.572 Try Clicking Company Name (TryCatch)
Private = False
Try
1.690 Group (Sequence)
Private = False
Activities
1.845 Click Company Name (NClick)
Activate = True
Click type = Single
Key modifiers = None
Mouse button = Left
Alter disabled element = True
Input mode = SameAsCard
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
Anchor 1
Strict selector =
Fuzzy selector =
Targeting methods = FuzzySelector, Image, CV
CV Control type = Text
CV Text = Current roles
CV Text = JGA
CV Control type = Icon
Strict selector = string.Format(, CompanyName)
Fuzzy selector = string.Format(, CompanyName)
Targeting methods = Selector, FuzzySelector
Private = False
1.800 Log Message (LogMessage)
LogLevel = UiPath.Core.Activities.LogLevel.Info
Message = Tried to click Company Info
Private = False
1.777 Delay (Delay)
Duration = 00:00:05
Private = False
1.774 Keyboard Shortcuts (NKeyboardShortcuts)
Activate = True
Click before typing = None
Shortcuts = [d(hk)][k(esc)][u(hk)]
Input mode = HardwareEvents
Private = False
1.765 Click To Expand Company Info (NClick)
Activate = True
Click type = Single
Key modifiers = None
Mouse button = Left
Input mode = SameAsCard
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
CV Text = View more details
CV Control type = Text
Strict selector =
Fuzzy selector =
Targeting methods = Selector, FuzzySelector
Private = False
1.736 Get Text ‘Overview’ (NGetText)
Text = CompanyInfo
Scraping method = Default
Target
Window selector (Application instance) =
Visibility check = Interactive
Responsive websites = False
Anchor 1
Strict selector =
Fuzzy selector =
Targeting methods = FuzzySelector, Image, CV
CV Control type = Text
CV Text = Overview
CV Control type = None
Strict selector =
Fuzzy selector =
Targeting methods = FuzzySelector
Private = False
1.691 Log Message (LogMessage)
LogLevel = UiPath.Core.Activities.LogLevel.Info
Message = Tried to get Company Overview
Private = False
Catches
Catch (Catch)
ExceptionType = System.Exception
Action
1.620 Log Message (LogMessage)
LogLevel = UiPath.Core.Activities.LogLevel.Info
Message = Process failed unfortunately due to a general exception
Private = False
Finally
1.667 Delay (Delay)
Duration = New TimeSpan(0, 0, (New Random().Next(30, 60)))
Private = False

EDIT - I have now changed all the flags to FALSE. Process still fails rather than treats as an exeption.

Thanks

1 Like

I feel like there could be two possibilities now

  1. Either the activity inside the catch block might be failing with exception

  2. Or If an activity within the Try block takes too long to execute and doesn’t complete within the timeout period, it may not be caught by the Catch block. You can adjust the TimeoutMS property of activities to handle longer-running activities.

May I know which activity u said was failing and is not caught
@Mark007

1 Like

@Palaniyappan

Currently 1.845, 1.765 and 1.736 should all fail and are not triggering an exception (1.845 oddly isn’t failing but passing through).

  1. Given the activity inside the catch block is a log message, can it really fail?

  2. I’ve extended all those activities to a 60 second time out and this doesn’t change the outcome.

Thanks, Mark

Following up on this @Palaniyappan I’ve created an example which I thought would not trigger an error due to Try Catch but does (I am purposefully ensuring the workflow fails to trigger the exception). You might recognise the webpage :slight_smile:

Any thoughts as to why this isn’t working would be greatly appreciated!

Thanks

Mark

Main.xaml (28.4 KB)

@Palaniyappan - any ideas how I can resolve this?

Thanks so much

Mark

@Mark007 I have been fighting with a similar issue. I ended up finding that only errors in the top level activity inside the Try block are caught.

For example, in this process the exception is not caught by the Try Catch (note the error activity is nested a level below the Try block):

1 Try Catch   
    Try
        1.1 Use Application: Notepad
            1.1.1 Throw (the activity that causes an exception)
    Catch
        System.Exception
             1.2 Message Box

In this process the exception is caught by the Try Catch (note the error activity is directly below the Try block).

1 Use Application: Notepad   
    1.1 Try Catch
        Try
            1.1.1 Throw (the activity that causes an exception)
        Catch
            System.Exception
                 1.1.2 Message Box

Very strange @kswanson. I assume in the first example you get a fatal error instead?

I get the StudioX “Something went wrong…” error when it is not caught by the Try Catch.