# Throwing exception from activity method is not working

**URL:** <https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902>\
**Category:** Community Support\
**Tags:** java-sdk, activity, workflow-options\
**Created:** [October 23, 2023, 9:01pm UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902 "2023-10-23T21:01:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjeet\_Kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sanjeet_kumar/32/4458_2.png) [@Sanjeet\_Kumar](https://community.temporal.io/u/Sanjeet_Kumar)\
**Post date:** [October 23, 2023, 9:01pm UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902/1 "2023-10-23T21:01:31Z")

</div>

I am throwing exception from an activity method and catching it in WorkflowMethod but getting exception. please help me

```auto
try {
    draftActivities.testException();
} catch (Exception e) {
    logger.error("exception = {}", e);
}

 @Override
public String testException() {
    logger.info("throwing exception");
// throw new Exception("exception thrown");
// throw Workflow.wrap(new Exception("ex"));
// throw new MyException("my exception");
// throw CheckedExceptionWrapper.wrap(new MyException("ex"));
// throw CheckedExceptionWrapper.wrap(new RuntimeException("ex"));
    throw Activity.wrap(new Exception("ex"));
}

```

```auto
java.lang.RuntimeException: Failure processing activity task. WorkflowID=8b323543-48e5-4e81-8479-92266bbbecee, RunID=2180ccf4-889a-4a98-9b25-d8f230384281, ActivityType=DraftActivities::test3, ActivityID=0
	at com.uber.cadence.internal.worker.ActivityWorker$TaskHandlerImpl.wrapFailure(ActivityWorker.java:206) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.worker.ActivityWorker$TaskHandlerImpl.wrapFailure(ActivityWorker.java:107) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.worker.PollTaskExecutor.lambda$process$0(PollTaskExecutor.java:76) ~[cadence-client-3.10.1.jar:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.ExceptionInInitializerError: null
	at com.uber.cadence.internal.sync.WorkflowInternal.wrap(WorkflowInternal.java:315) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.activity.Activity.wrap(Activity.java:343) ~[cadence-client-3.10.1.jar:na]
	at com.saison.omni.draftworkflow.activity.DraftActivitiesImpl.test3(DraftActivitiesImpl.java:288) ~[main/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at com.uber.cadence.internal.sync.POJOActivityTaskHandler$POJOActivityImplementation.execute(POJOActivityTaskHandler.java:224) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.sync.POJOActivityTaskHandler.handle(POJOActivityTaskHandler.java:200) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.worker.ActivityWorker$TaskHandlerImpl.handle(ActivityWorker.java:144) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.worker.ActivityWorker$TaskHandlerImpl.handle(ActivityWorker.java:107) ~[cadence-client-3.10.1.jar:na]
	at com.uber.cadence.internal.worker.PollTaskExecutor.lambda$process$0(PollTaskExecutor.java:71) ~[cadence-client-3.10.1.jar:na]
	... 3 common frames omitted

```

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [October 24, 2023, 1:24am UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902/2 "2023-10-24T01:24:39Z")

</div>

> [@Sanjeet\_Kumar](#):
>
> `java.lang.ExceptionInInitializerError`

is the exception that occurred during a static initialization that caused this error to be created.

So make sure that none of the static initializers in your code throws.

---

<div class="post-metadata">

**Author:** ![Sanjeet\_Kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sanjeet_kumar/32/4458_2.png) [@Sanjeet\_Kumar](https://community.temporal.io/u/Sanjeet_Kumar)\
**Post date:** [October 24, 2023, 5:42am UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902/3 "2023-10-24T05:42:37Z")

</div>

@maxim there is no static initialization.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [October 24, 2023, 1:43pm UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902/4 "2023-10-24T13:43:34Z")

</div>

You need to find out what throws that exception or provide a reproduction we could run. I’ve never seen this problem before.

---

<div class="post-metadata">

**Author:** ![Sanjeet\_Kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/sanjeet_kumar/32/4458_2.png) [@Sanjeet\_Kumar](https://community.temporal.io/u/Sanjeet_Kumar)\
**Post date:** [October 25, 2023, 10:30am UTC](https://community.temporal.io/t/throwing-exception-from-activity-method-is-not-working/9902/5 "2023-10-25T10:30:28Z")

</div>

Thanks @maxim, the issue is resolved now. I was using java 17 because of which i faced the issue.
