Rethinking Errors: Learning from Scala and Go

Bruce Eckel (Mindview, LLC)
Location: D136 Level: Novice
Average rating: ***..
(3.43, 14 ratings)
Slides:   1-HTM 

Exceptions were designed for “exceptional conditions,” when you simply don’t know what to do within your current context. C++ steered us toward using exceptions for error reporting and Java institutionalized it. And yet, sometimes it seems akin to pulling a fire alarm when the floor gets dirty, the sink clogs or the dog has an accident.

What should we do instead? Certainly, some conditions justify exceptions, but numerous others are expected errors; Forcing the caller to use try and except right at the call site seems overkill. C showed us that returning special values never worked out very well — we could never settle on the values and the resulting interface didn’t make it clear enough to the caller that they should respond to error conditions.

The standard error-reporting practice in the Go language is to return a tuple holding success and null-or-failure objects, while in Scala you return a disjoint union that can be either a success object or a failure object. Both cases require the programmer to analyze the result; you can no longer just assume the result is valid. This produces the same effect as checked exceptions (that is, you can’t ignore the fact that the expression might fail) but without the visual noise and distraction of exception handling.

Based on the Scala and Go approaches, I’ll show how you can modify your Python coding style to produce more robust error handling.

Photo of Bruce Eckel

Bruce Eckel

Mindview, LLC

Bruce Eckel is the author of Thinking in Java and Thinking in C++, and a number of other books on computer programming. He’s been in the computer industry for 30 years and tends to reach for Python when he needs to solve real problems. He’s given hundreds of presentations around the world and enjoys putting on alternative conferences and events like The Java Posse Roundup. He is currently studying organizational dynamics, trying to find a new way to organize companies so that working together becomes a joy; you can read about his struggles in this arena at, while his programming work can be found through

Comments on this page are now closed.


Picture of Bruce Eckel
Bruce Eckel
07/26/2013 3:35am PDT

I uploaded the slides to the OSCON site/service (as requested by OSCON) the night before the presentation. Not sure if there’s just a delay in posting or if it’s just obscure to find them.

George Shields
07/25/2013 7:40am PDT

Could you post the slides? Thanks


Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at the conference, contact Sharon Cordesse at (707) 827-7065 or

Contact Us

View a complete list of OSCON contacts