# Are custom exception types automatically serializable in a StatusReply?

**URL:** <https://discuss.akka.io/t/are-custom-exception-types-automatically-serializable-in-a-statusreply/10791>\
**Category:** Akka Cluster\
**Tags:** akka-typed, scala, akka-cluster\
**Created:** [June 25, 2024, 3:32pm UTC](https://discuss.akka.io/t/are-custom-exception-types-automatically-serializable-in-a-statusreply/10791 "2024-06-25T15:32:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dakins](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dakins](https://discuss.akka.io/u/dakins)\
**Post date:** [June 25, 2024, 3:32pm UTC](https://discuss.akka.io/t/are-custom-exception-types-automatically-serializable-in-a-statusreply/10791/1 "2024-06-25T15:32:22Z")

</div>

If I create my own exception object/class/type, e.g.

```auto
case object MyError extends Throwable
case class MyOtherError(msg: String) extends Throwable("the other error")

```

And then send these errors in a clustered system that has java-serialization disabled and uses custom serializers:

```auto
val ex1 = MyError
val ex2 = MyOtherError("user not found")
actorRef1 ! StatusReply.error(ex)
actorRef2 ! StatusReply.error(ex2)

```

Will my custom errors fail to be serialized? Or is the built in serializer for StatusReply able to serialize MyError and MyOtherError?

I see that in the [StatusReply.error api](https://doc.akka.io/api/akka/current/akka/pattern/StatusReply$.html#error%5BT%5D(exception:Throwable):akka.pattern.StatusReply%5BT%5D) it says: “Also note that Akka does not contain pre-build serializers for arbitrary exceptions.”

But I also see in the [generic response wrapper documentation](https://doc.akka.io/docs/akka/current/typed/interaction-patterns.html#generic-response-wrapper) it says “Akka includes pre-built serializers for the type, so in the normal use case a clustered application **only needs to provide a serializer for the successful result.** ” (my emphasis).

So would this work or would I need to define and link custom serializers for MyError and MyOtherError?

---

<div class="post-metadata">

**Author:** ![leviramsey](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/leviramsey/32/2653_2.png) [@leviramsey](https://discuss.akka.io/u/leviramsey)\
**Post date:** [June 25, 2024, 5:16pm UTC](https://discuss.akka.io/t/are-custom-exception-types-automatically-serializable-in-a-statusreply/10791/2 "2024-06-25T17:16:14Z")

</div>

[akka/akka-remote/src/main/scala/akka/remote/serialization/MiscMessageSerializer.scala at 1054cc8eb9c96d013d5c2cde0be8292f92f909e0 · akka/akka · GitHub](https://github.com/akka/akka/blob/1054cc8eb9c96d013d5c2cde0be8292f92f909e0/akka-remote/src/main/scala/akka/remote/serialization/MiscMessageSerializer.scala#L131) is how the `StatusReply`s are serialized.

Note that the recommended usage is to not send the full exception across the wire, but just a string message (the full exception is somewhat akin to leaking a full exception and stacktrace in a web UI); the generic response wrapper docs only illustrate sending a string. But if a custom exception is an effective way of including useful data for an asker (e.g. “there’s no point in retrying before this time”), you would have to register a serializer for the exception and then the exception will be serialized.

---

<div class="post-metadata">

**Author:** ![kahunroles](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/kahunroles/32/3218_2.png) [@kahunroles](https://discuss.akka.io/u/kahunroles)\
**Post date:** [February 1, 2025, 10:11am UTC](https://discuss.akka.io/t/are-custom-exception-types-automatically-serializable-in-a-statusreply/10791/5 "2025-02-01T10:11:13Z")

</div>

Thanks for giving solution[.](https://7-brewsecretmenu.us/7-brew-coffee-locations/)
