I want to throw an exception using stream when I find an element by condition
myList.stream()
.filter(d -> (d.getNetPrice() != new BigDecimal(0)))
.findAny()
.orElseThrow(
() -> new DocumentRequestException("The product has 0 'NetPrice' as a value"));
for request
{
"sku": "123",
"quantity": 3,
"description": "pc",
"netPrice": 16806,
"amount": 50418
},
{
"sku": "1234",
"quantity": 2,
"description": "notebook",
"netPrice": 0,
"amount": 0
}
So for that example I want the exception because the list contains one element with 'netPrice' = 0 but the code return the Pc element and nothing else happend
how can I fix it?