Skip to content

Commit f83abfb

Browse files
Avoided usage of RuntimeException
1 parent 2aebb8c commit f83abfb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/main/java/edu/ie3/datamodel/io/processor/Processor.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,20 @@ protected String processMethodResult(Object methodReturnObject, Method method, S
236236
((Optional<?>) methodReturnObject)
237237
.map(
238238
o -> {
239-
try {
240-
if (o instanceof Quantity<?>) {
241-
return handleQuantity((Quantity<?>) o, fieldName);
242-
} else {
243-
throw new EntityProcessorException(
244-
"Handling of "
245-
+ o.getClass().getSimpleName()
246-
+ ".class instance wrapped into Optional is currently not supported by entity processors!");
247-
}
248-
} catch (EntityProcessorException e) {
249-
throw new RuntimeException(e);
239+
if (o instanceof Quantity<?>) {
240+
return Try.of(
241+
() -> handleQuantity((Quantity<?>) o, fieldName),
242+
EntityProcessorException.class);
243+
} else {
244+
return Failure.of(
245+
new EntityProcessorException(
246+
"Handling of "
247+
+ o.getClass().getSimpleName()
248+
+ ".class instance wrapped into Optional is currently not supported by entity processors!"));
250249
}
251250
})
252-
.orElse(""));
251+
.orElse(Success.of("")) // (in case of empty optional)
252+
.getOrThrow());
253253
case "ZonedDateTime" -> resultStringBuilder.append(
254254
processZonedDateTime((ZonedDateTime) methodReturnObject));
255255
case "OperationTime" -> resultStringBuilder.append(

0 commit comments

Comments
 (0)