Exception handling issue

studio
exception

#1

Hi All,
My question is regarding Exception handling. When exception which is thrown by activity handled by catch block ,it take times to execute next activity.is there any solution to reduce that time?

Regards,
SagarSB


#2

Hi @SagarSB

What do you mean when you say the ‘next activity’?

If you mean it is taking a long time to throw and handle the exception before moving on, then this is likely because the activity which is throwing the exception will probably be waiting for its timeout period to expire before the exception is thrown and handled (this would be the case for automation activities like click etc.), The default timeout is 30 seconds but this can be changed in the ‘TimeoutMS’ property of the activity, which is in milliseconds so 1 second is 1000 millisecond.

I hope this helps!


#3

Hello @SagarSB, could you give more informations on what the activities inside and around are, or possibly, a sample on this?


#4

Hi,
The problem I’m facing is to open a workbook and if the workbook does not exist on the specified path, it will show a message box (Exception Handled) saying “File does not exist” but after that my workflow should stop, but it is not getting terminated by the bot. So how can I stop the execution?

Thanks & Regards,
Gunjan Bhogal


#5

Thank you…My issue is solved @Djh


#6

If the exception is thrown and then caught in the catch block, it will execute the activities in the catch block and then continue, because what is in the catch block should effectively ‘deal with’ the exception. if you want the automation to actually stop dead when an exception is thrown then do not catch it in a try catch. ( note that this is not a good way of developing as it is not a controlled stop of the automation…)


#7

:slight_smile:


#8

Thanks…


#9

@Djh please resolve Gunjan’s issue …which is mentioned above


#10

If the exception is thrown and then caught in the catch block, it will execute the activities in the catch block and then continue, because what is in the catch block should effectively ‘deal with’ the exception. if you want the automation to actually stop dead when an exception is thrown then do not catch it in a try catch. ( note that this is not a good way of developing as it is not a controlled stop of the automation…)


#11

Hi @Djh,

I’m attaching my Xaml file. In this, I’m opening a pdf and then scraping data from it. Now, if the file not found exception comes it should stop the execution just after showing the message box, but it’s not working in the expected way. It waits for the scrapped element and then returns another exception saying “Element not found”.

And the second problem I’m facing is to use properly specified exceptions, for example in my Xaml file I have passed 2 exceptions: first one is “FileNotFoundException” and the other one is “System.Exception”, but it does not catches the former one, it only catches the latter exception and shows the message box bonded with that exception.

Thanks & Regards,
Gunjan Bhogal

Main.xaml (18.0 KB)


#12

Hi @gunjanbhogal

For your first point, it is as i said above, because you are catching the exception being thrown and handling it in the catch block, the automation will continue on to the next activity (trying to read the PDF using OCR) because in using the try catch block you have told the automation that you have handled the exception in the way you cant to using the catch block, and to continue with its work. SO - if you want to stop the automation dead when this application occurs, the simplest way would be to add a rethrow activity after your message box, that way you are letting the automation that you have not handled the exception and the automation will stop as it has nothing else it can do.

For your second point, in UiPath you have exposure to many different exception types, however the one which will be thrown as standard will be (as far as im aware) always a system.exception. in order to access the other exception types you can either change the type of an exception thrown (advanced), or throw an exception with the correct type.


#13

Hi @Djh

I added the rethrow activity but it’s not helping me, it stops the execution but throws an exception. What I want is to stop the execution after handling the exception.

And for the second one- Correct me if I’m wrong, for File Not Found type of exceptions the correct type would be “System.IO.FileNotFoundException”?


#14

Hi @gunjanbhogal, for the first one, - remove the rethrow we just put in, then - add all of your other activities (reading PDF via OCR etc) into the TRY section of the try catch.

this means that the try will contain everything, and the catch will contain the message box, and after the message box executes the automation should end.

Regarding the second, yes, so something like:
image

but you will need to throw this using the throw activity, one way to do this would be to check to see if the file exists using a file exists activity, then an if statement like this:


#15

How can we get the activity details in the exception type while handling the exception ?
I want to get the exact activity name or type of the activity in which the exception is occurring
what type exception should we use to get it done?


#16

try by using exception.Source