HeadlinesBriefing favicon HeadlinesBriefing.com

Why Go Won't Adopt try Keyword: Error System Legacy

Hacker News •
×

Go developers have long envied Rust and Zig's concise error handling syntax. While those languages use try to handle errors in a single line, Go remains stuck with verbose if err != nil checks. The common explanation about Go's preference for explicitness misses the deeper issue: Go's error system is fundamentally incompatible with modern error handling approaches.

Zig actually enforces more explicit error handling than Go through its compiler-known error sets. Every function's potential failures are declared in its return type, and the compiler won't compile code that misses handling cases. Go's pattern, while verbose, is only a convention - developers can silently ignore errors using underscore assignment. This reveals that Go's celebrated explicitness is partly an illusion.

The real barrier is Go's error interface design. The simple type error interface {Error() string} definition means any type with that method works as an error. This flexibility enables rich error context through wrapping but prevents compile-time guarantees. Adding try would be mere syntax sugar without fixing this underlying type system limitation.