# Extending mapException to allow filtering based on rootCause

**URL:** <https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147>\
**Category:** Flowable Engine\
**Created:** [June 20, 2018, 1:29pm UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147 "2018-06-20T13:29:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aturkovic](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aturkovic/32/711_2.png) [@aturkovic](https://forum.flowable.org/u/aturkovic)\
**Post date:** [June 20, 2018, 1:29pm UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/1 "2018-06-20T13:29:47Z")

</div>

Flowable Engine throws FlowableExceptions in almost every case, and sometimes it is difficult to write proper `<flowable:mapException>` tags to cover them since we can’t know the root cause if we want to handle them differently.

For an example:

`org.flowable.http.HttpActivityExecutor` wraps `ClientProtocolException`, `IOException`, `URISyntaxException` and exceptions thrown by `httpRequestHandler` or `httpResponseHandler` into `FlowableException`. If we use `<flowable:mapException>` we cannot distinct if the root cause is because of an invalid URL or because of our custom `HttpRequestHandler`.

I would like to propose a new attribute for the `<flowable:mapException>` tag, `rootCause` which would allow to map exceptions based on the root cause of the exception.

For an example:

`<flowable:mapException errorCode="myErrorCode1" rootCause="java.net.URISyntaxException">org.flowable.SomeException</flowable:mapException>` which would handle all `org.flowable.SomeException` caused by `java.net.URISyntaxException`.

Does this sound like wrong design or a good feature? If it sounds useful, I would happily submit a PR with an example.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [June 26, 2018, 9:38am UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/2 "2018-06-26T09:38:32Z")

</div>

There seems to be support for that already, see [https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/helper/ErrorPropagation.java#L343](https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/helper/ErrorPropagation.java#L343) : from that code, it looks like if the boolean flag ‘andChildren’ is added and set to true, the exception should match for subclasses too. I don’t find tests for this though, so not sure if it works properly.

---

<div class="post-metadata">

**Author:** ![aturkovic](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aturkovic/32/711_2.png) [@aturkovic](https://forum.flowable.org/u/aturkovic)\
**Post date:** [June 26, 2018, 9:43am UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/3 "2018-06-26T09:43:31Z")

</div>

I might be mistaken, but that seems like the opposite of this? I agree it is implemented right, but it is a different feature.

`<flowable:mapException errorCode="myErrorCode1" andChildren="true">org.flowable.SomeException</flowable:mapException>`

Would catch all `org.flowable.SomeException` and it’s subclasses. That seems totally fair.

`<flowable:mapException errorCode="myErrorCode1" rootCause="java.net.URISyntaxException">org.flowable.SomeException</flowable:mapException>`

Would however catch `org.flowable.SomeException` ONLY if it was caused by a `java.net.URISyntaxException`, something like `throw new SomeException((java.net.URISyntaxException) e)`

The difference here is that I would like to handle `FlowableException` only if it was caused by a specific exception. Flowable engine wraps all exceptions and there is currently no way (that I know of) on how to handle different causes through BPMN flow using `flowable:mapException`.

Hope that clarifies my intention a little.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [June 26, 2018, 9:57am UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/4 "2018-06-26T09:57:38Z")

</div>

Ok, i see your point. I understood it indeed backwards. Thanks for the proper clarification :-).

Your idea makes indeed sense and would be good to have.  
Alternatively, I was thinking that having a specific (new) type of exception would also solve this maybe better? So instead of throwing FlowableException, have specific FlowableXyzException instead. Wdyt?

---

<div class="post-metadata">

**Author:** ![aturkovic](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aturkovic/32/711_2.png) [@aturkovic](https://forum.flowable.org/u/aturkovic)\
**Post date:** [June 26, 2018, 10:02am UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/5 "2018-06-26T10:02:53Z")

</div>

Flowable documentation said that they wouldn’t like a big exception hierarchy and would like to keep exceptions down to as few as possible.

More about that here: [https://flowable.org/docs/userguide/index.html#\_exception\_strategy](https://flowable.org/docs/userguide/index.html#_exception_strategy)

---

<div class="post-metadata">

**Author:** ![aturkovic](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aturkovic/32/711_2.png) [@aturkovic](https://forum.flowable.org/u/aturkovic)\
**Post date:** [June 27, 2018, 4:58pm UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/6 "2018-06-27T16:58:05Z")

</div>

Created a new PR here:[https://github.com/flowable/flowable-engine/pull/1162](https://github.com/flowable/flowable-engine/pull/1162)

---

<div class="post-metadata">

**Author:** ![aturkovic](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/aturkovic/32/711_2.png) [@aturkovic](https://forum.flowable.org/u/aturkovic)\
**Post date:** [July 9, 2018, 7:28am UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/7 "2018-07-09T07:28:22Z")

</div>

Any opinions on this?

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [July 20, 2018, 8:33pm UTC](https://forum.flowable.org/t/extending-mapexception-to-allow-filtering-based-on-rootcause/2147/8 "2018-07-20T20:33:49Z")

</div>

PR merged, so all good 🙂
