# How do you gracefully handle "actor died"?

**URL:** <https://discuss.ray.io/t/how-do-you-gracefully-handle-actor-died/14012>\
**Category:** Ray Core\
**Created:** [March 15, 2024, 12:28am UTC](https://discuss.ray.io/t/how-do-you-gracefully-handle-actor-died/14012 "2024-03-15T00:28:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hapi](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@Hapi](https://discuss.ray.io/u/Hapi)\
**Post date:** [March 15, 2024, 12:28am UTC](https://discuss.ray.io/t/how-do-you-gracefully-handle-actor-died/14012/1 "2024-03-15T00:28:19Z")

</div>

Please consider the following toy application:

```auto
import ray

class DowningToolsError(Exception):
    pass

@ray.remote
class Supervisor:

    def __init__ (self):

        print('Supervisor working')

        self._worker1 = Worker1.remote()
        
        try:
            self._worker2 = Worker2.remote()

        except DowningToolsError:
            print(f"Worker did not like that idea! Let's try another plan!")

@ray.remote
class Worker1:

    def __init__ (self):

        print('Worker1 working')

@ray.remote
class Worker2:

    def __init__ (self):

        raise DowningToolsError('You must be kidding me!')

if __name__ == ' __main__':

    Supervisor = Supervisor.remote()

    while True:
        pass

```

What do I have to do instead of:

```auto
  except DowningToolsError:
      print(f"Worker did not like that idea! Let's try another plan!")

```

to make Supervisor gracefully handle Worker2’s failure?

I have tried the following:

```auto
except ray.exceptions.RayActorError:
    print(f"Worker2 is not available. Let's try another plan!")

```

but that did not have the desired effect.

Any suggestions would be much appreciated!

I

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [March 17, 2024, 4:51am UTC](https://discuss.ray.io/t/how-do-you-gracefully-handle-actor-died/14012/2 "2024-03-17T04:51:08Z")

</div>

Hi @Hapi ,

`Worker2.remote()` shouldn’t throw exceptions. Exceptions are thrown when you actually call actor method like

```auto
try:
   ray.get(self._worker2.some_method.remote())
except: ray.exceptions.RayActorError:
   ....

```

---

<div class="post-metadata">

**Author:** ![Hapi](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@Hapi](https://discuss.ray.io/u/Hapi)\
**Post date:** [March 17, 2024, 12:53pm UTC](https://discuss.ray.io/t/how-do-you-gracefully-handle-actor-died/14012/3 "2024-03-17T12:53:49Z")

</div>

In my real application, worker2 connects to an external websockets server, and it does this in its **init** method. If the websockets server is unavailable, the connection errors, and I need to catch it somewhere, so I can close everything down gracefully. I’m curious how other people handle similar situations in ray?
