I have a nested try > catch situation where the inner catch inside a loop is checking for a possible expected exception. All this works fine for the first iteration of the loop. If a duplicate is found it is reported and it moves on to the second time round and if another duplicate is found then it throws the outer exception, not the inner one. There is probably a good / obvious reason for this but it escapes me and my research.
Assistance much appreciated. Java code looks like this:
try {
// do some stuff
for(Enumeration e=wholeResult.enumerateProduct();e.hasMoreElements();){
tmpProduct = (Product)e.nextElement();
// do some stuff
try {
db.begin();
db.create(productCategory);
db.commit();
result.addProduct(tmpProduct);
cat.debug("Added " + tmpProduct.toString() + " to " + category.toString());
}
catch (org.exolab.castor.jdo.DuplicateIdentityException err) {
// Enters here first time only
cat.debug("Error caught");
try {
db.rollback();
} catch(TransactionNotInProgressException TnipE) {
}
cat.debug("SKIPPED - " + tmpProduct.toString() + " already in category " + category.toString());
}
}
// do some stuff
}
catch(Exception e) {
// Enters here second time
cat.error("Exception in CategoryAddBulkProductsAction: " + e.toString());
throw e;
}
Debug output / exception:
542 DEBUG [ajp-bio-8009-exec-1] () - Error caught
542 DEBUG [ajp-bio-8009-exec-1] () - SKIPPED - Item with two prices : Item With Two Prices (#99751) already in category Buy Online (#2281)
542 DEBUG [ajp-bio-8009-exec-1] () - Working with Sale Item : My Order Item (#127681)
548 ERROR [ajp-bio-8009-exec-1] () - Exception in CategoryAddBulkProductsAction: org.exolab.castor.jdo.TransactionAbortedException: Nested error: org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for object of type model.objects.ProductCategory with identity <497(497),127681(127681),2281(2281)>: an object with the same identity already exists in persistent storage: Duplicate identity found for object of type model.objects.ProductCategory with identity <497(497),127681(127681),2281(2281)>: an object with the same identity already exists in persistent storage
550 DEBUG [ajp-bio-8009-exec-1] () - Some kind of error occured
550 ERROR [ajp-bio-8009-exec-1] () - org.exolab.castor.jdo.TransactionAbortedException: Nested error: org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for object of type model.objects.ProductCategory with identity <497(497),127681(127681),2281(2281)>: an object with the same identity already exists in persistent storage: Duplicate identity found for object of type model.objects.ProductCategory with identity <497(497),127681(127681),2281(2281)>: an object with the same identity already exists in persistent storage
org.exolab.castor.jdo.DuplicateIdentityException?DuplicateIdentityExceptionis wrapped in an outer exception.try/catchclauses don't look at any wrapped exceptions when determining what to catch.