2 ms·
Usually what you want is to go through the rest of the rows, finish the batch and close the transaction, and then handle all the errored rows at a higher level.
by lmm 4y ago
Usually what you want is to go through the rest of the rows, finish the batch and close the transaction, and then handle all the errored rows at a higher level. "Bubble up by default" works in simple cases but falls apart as soon as you're doing any remotely high-throughput work (which has to mean chunk-at-a-time processing decoupled from the orchestration), and ends up doing more harm than good, IME. And note that in Java it's outright impossible to catch exceptions from a generic expression while preserving their type - you have to copy/paste your functions for each number of possible exception types you want to be able to handle.
- kaba0 4y agoI don’t see why this wouldn’t be performant: void transactionBoundary() { var list = someLongListOfElems; var resultList = List.of(); // a sum type for success and error conditions for (var l : list) { try { resultList.add(process(l)); } catch (SpecificException e) { // add to resulList or errorList or whatever to further process those instances. // You can just use SpecificException’s fields … } } }