Throwing exception from activity method is not working

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

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"));
}
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

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.

@maxim there is no static initialization.

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

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

1 Like