Re:Learning C# and .NET after two decades of programming
by vips7L on Sunday March 02, 2025 @07:17AM
(#43229692)
Checked exceptions are represented in the type system. There is fundamentally no difference between these two:
A b() throws C
fn b() -> Result<A, C>
A a = try {
b()
} catch (C c) {
new A()
}
val a = b() match {
Ok(a) => a
Failure(c) => A()
}
Pattern matching, nullable types, and the Try* method conventions are also ways of representing the potential for failure explicitly.