# Unable to catch TransientException

**URL:** <https://community.neo4j.com/t/unable-to-catch-transientexception/41632>\
**Category:** Java\
**Tags:** cypher, operations\
**Created:** [July 19, 2021, 10:30am UTC](https://community.neo4j.com/t/unable-to-catch-transientexception/41632 "2021-07-19T10:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsaurabh](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jsaurabh/32/19258_2.png) [@jsaurabh](https://community.neo4j.com/u/jsaurabh)\
**Post date:** [July 19, 2021, 10:30am UTC](https://community.neo4j.com/t/unable-to-catch-transientexception/41632/1 "2021-07-19T10:30:00Z")

</div>

Hi,

I have facing a issue when I am trying to catch TransientException exception for below code:

StatementResult result = runQuery(sb.toString(), entity.getAllProperties());  
Record record = null;  
try {  
int retryCnt = 0;  
while(retryCnt++ \<= MAX\_NEO4J\_RETRY\_CNT) {  
try {  
record = result.single();  
break;  
}catch (TransientException e) {  
if(retryCnt \>= MAX\_NEO4J\_RETRY\_CNT) {  
logger.warn("Giving up entity query " + entity.getSureName() + ", after " + retryCnt + " retries");  
throw e;  
}  
logger.warn("Retrying Entity query for : " + entity.getSureName());  
try {  
TimeUnit.SECONDS.sleep(1);  
} catch (InterruptedException e1) {  
}  
}  
}  
}catch (NoSuchRecordException e) {  
return entity;  
}

record = result.single(); throws TransientException and the above code catches it. However retry code never gets executed as I don’t the log messages. Attaching the exception trace, I can see that TransientException is getting suppressed. Can you please help me if there any other way to handle this exception.

Regards  
Saurabh  
[Neo4J.txt](https://community.neo4j.com/uploads/short-url/uC3zhHmJz2ZXT1a32EE7M1cgH2Y.txt) (7.6 KB)

---

<div class="post-metadata">

**Author:** ![jsaurabh](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jsaurabh/32/19258_2.png) [@jsaurabh](https://community.neo4j.com/u/jsaurabh)\
**Post date:** [July 20, 2021, 5:21am UTC](https://community.neo4j.com/t/unable-to-catch-transientexception/41632/2 "2021-07-20T05:21:42Z")

</div>

Hi

I changed the catch to handle all Exception than also retry code is not executed. Can someone please help on how to make this work.

Regards  
Saurabh

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [July 20, 2021, 9:45am UTC](https://community.neo4j.com/t/unable-to-catch-transientexception/41632/3 "2021-07-20T09:45:50Z")

</div>

I don't really see how the code you share matches the stack trace you provided.  
In particular:

```java
org.neo4j.driver.v1.exceptions.TransientException: ForsetiClient[70] can't acquire ExclusiveLock{owner=ForsetiClient[9]} on NODE(107292252), because holders of that lock are waiting for ForsetiClient[70].
 Wait list:ExclusiveLock[
Client[9] waits for [14,70]]
	at org.neo4j.driver.internal.util.Futures.blockingGet(Futures.java:123)
	at org.neo4j.driver.internal.ExplicitTransaction.close(ExplicitTransaction.java:117)
	at com.nokia.mdf.sure.neo.repo.ScopingDataSourceImpl.endTransactionScope(ScopingDataSourceImpl.java:199) <------- your code ends here
	at com.nokia.mdf.sure.neo.repo.SureDBN4jCommand.executeWrite(SureDBN4jCommand.java:121)
	at com.nokia.mdf.sure.neo.repo.SureDBN4jCommand.execute(SureDBN4jCommand.java:222)
	at com.nokia.oss.sure.proc.init.NeoExecute.execute(NeoExecute.java:27)

```

What's happening at `com.nokia.mdf.sure.neo.repo.ScopingDataSourceImpl.java` on line 199?  
Is it surrounded by a try-catch block with `TransientException`?

---

<div class="post-metadata">

**Author:** ![jsaurabh](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jsaurabh/32/19258_2.png) [@jsaurabh](https://community.neo4j.com/u/jsaurabh)\
**Post date:** [August 4, 2021, 12:12pm UTC](https://community.neo4j.com/t/unable-to-catch-transientexception/41632/4 "2021-08-04T12:12:56Z")

</div>

Hi,

Thanks for your, below stack trace matches my code. This stack trace is at the end of file.

Regards  
Saurabh  
Suppressed: org.neo4j.driver.internal.util.ErrorUtil$InternalExceptionCause  
at org.neo4j.driver.internal.util.Futures.blockingGet(Futures.java:123)  
at org.neo4j.driver.internal.InternalStatementResult.blockingGet(InternalStatementResult.java:134)  
at org.neo4j.driver.internal.InternalStatementResult.single(InternalStatementResult.java:81)  
at com.nokia.mdf.sure.neo.dao.GenericDaoExt.checkAssociationEntity(GenericDaoExt.java:1842)  
at com.nokia.oss.sure.proc.init.NeoDBActions$10.doExecute(NeoDBActions.java:355)  
at com.nokia.mdf.sure.neo.repo.SureDBN4jCommand.executeWrite(SureDBN4jCommand.java:87)  
... 13 more
