# Try-Catch does not catch, breaks the script run

**URL:** <https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757>\
**Category:** Bugs\
**Created:** [March 30, 2020, 10:12pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757 "2020-03-30T22:12:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [March 30, 2020, 10:12pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/1 "2020-03-30T22:12:50Z")

</div>

I have a try-catch in which I enumerate files and use async action to run 4 threads, which in turn run same target in which I check file for digital signature and sign it if signature is missing.  
Periodically, this logic is breaking but that is not the question here. The problem is that script does not catches the exception, it just stops its run.

This is build script setup

![Build script setup](https://www.finalbuilder.com/forums/uploads/default/original/2X/5/57e8a14078f675ab5967d8e97641e4ae4a87e9ce.png)

This is log file

![Script stopped](https://www.finalbuilder.com/forums/uploads/default/original/2X/a/aadfcb44d668558aed2ede8243cbaa44c357640b.png)

As you see, script just exits and nothing handled. Thank you

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [March 30, 2020, 10:24pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/2 "2020-03-30T22:24:30Z")

</div>

please send your project file to support @ [finalbuilder.com](http://finalbuilder.com) so we can try to reproduce it here. Ideally, if you can narrow it down to a small test project that would result in a faster resolution.

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [March 30, 2020, 10:25pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/3 "2020-03-30T22:25:29Z")

</div>

Also, what version/build of FinalBuilder are you using?

---

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [March 30, 2020, 11:04pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/4 "2020-03-30T23:04:07Z")

</div>

FB v8.0.0.2442. Thank you

---

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [March 31, 2020, 12:32am UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/5 "2020-03-31T00:32:55Z")

</div>

@Vincent Thank you. I’ve sent the file over. I cut out the piece in question and tested it - it runs. More description is in email.  
PS: Additionally, I experimented with “Raise Exception” and if I place it in one or 2 of the thread action groups, it would wait until other threads exited and then go into catch as expected.

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [March 31, 2020, 12:59am UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/6 "2020-03-31T00:59:00Z")

</div>

I’ve had a play with your project, but unfortunately it does not reproduce the problem.

That said, this project has some design issues.

Using multiple threads in this way to process a fileset is not a good idea. I can see what you are trying to achieve, however a much simpler option is to use a queue.

We have an example project here

> **[VSoftTechnologies/FinalBuilder.Examples](https://github.com/VSoftTechnologies/FinalBuilder.Examples/tree/master/FB8/ParallelQueue)**
>
> Example FinalBuilder Projects. Contribute to VSoftTechnologies/FinalBuilder.Examples development by creating an account on GitHub.

This project shows how to use multiple threads to process items in a queue. To add the fileset to the queue, you can use this expression

```
%_finalDigiSignFiledset.ALLFILES:sep=crlf%

```

This will add each file to the queue. I would recommend experimenting with the number of threads to get the best performance, as more threads does not automatically mean better performance.

In your processing target you should handle exceptions with a try catch, and set a variable to indicate that an error occurred. ~~Otherwise the async group will just receive the exception and stop all threads.~~

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [March 31, 2020, 1:09am UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/7 "2020-03-31T01:09:50Z")

</div>

> [@anatoliy.schmoukler](#):
>
> PS: Additionally, I experimented with “Raise Exception” and if I place it in one or 2 of the thread action groups, it would wait until other threads exited and then go into catch as expected.

Hmm… not sure if that is the intended behaviour but I just tested and see that. I suspect this changed somewhere along the way, as

---

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [March 31, 2020, 1:34am UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/8 "2020-03-31T01:34:08Z")

</div>

Ok. I will rework it using a queue. Thank you. Yes, when real signing is going on, it works 3 times out of 4. Without signing, it worked every time. Just curious at this time - is it possible that simultaneous access to fileset count could cause this? Or it is somehow connected to a network disruption during signing. It is true that sometimes these digisign servers are to busy or something like that. Thank you for all the tips!

---

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [March 31, 2020, 10:15pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/9 "2020-03-31T22:15:33Z")

</div>

Ok, Sir. Implemented queue-based logic. It works. Will see if it breaks again in real time digital signing.

---

<div class="post-metadata">

**Author:** ![anatoliy.schmoukler](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/8dc957/32.png) [@anatoliy.schmoukler](https://www.finalbuilder.com/forums/u/anatoliy.schmoukler)\
**Post date:** [April 10, 2020, 7:35pm UTC](https://www.finalbuilder.com/forums/t/try-catch-does-not-catch-breaks-the-script-run/6757/10 "2020-04-10T19:35:20Z")

</div>

@Vincent There were at least 5 builds since I changed the action and so far not one fail due to same issue. Thanks
