Exceptions
& Streams

@benjiweber

@benjiweber

http://tech.unruly.co

I <3 Java

with((Anon & Quacks & Waddles)i->i, ducklike -> {
    ducklike.quack();
    ducklike.waddle();
});
                    

Why Exceptions?

Streams

Happy

Structure

Checked Exceptions

Alternatives

Java 8 to the Rescue

Takeaway

Transform other people's code into your style,
without modifying it

Checked Exceptions

Unfortunate Use

UnsupportedEncodingException

SqlException

IOException

Judicious Use vs Overuse

…prior to Java 8

Streams & CompletableFutures

change things

Java 8

Problem & Solution

Alternatives to Checked Exceptions

null

"It's not working"

Optional<T>

Safer but Verbose & Vague

Runtime Exceptions

Either<T, E>

@ScottWlaschin

But what about Streams?

…and what about everyone else's code?

Java 8 to the Rescue

Resistance is Futile

Your checked exceptions will adapt to service us

Code is Data

Transform & Wrap

Works for each alternative

Checked Exceptions
equivalent to
Either

Translatable

…my methods work with Customers, not Eithers

Apply the same technique

Either<T, E>

@ScottWlaschin

Wrapping up

Checked Exceptions

Alternatives

Transform code to Alternative

Transform code, just like data.

Thanks for Listening!

http://benjiweber.com/talks/exceptions-and-streams

http://github.com/benjiman/exceptions-and-streams

@benjiweber

http://benjiweber.com/java

Any questions?