今日已更新 255 条资讯 | 累计 24914 条内容
关于我们

Without Exception: How Neander Programs Fail

Dirk Mattig 2026年07月28日 11:50 0 次阅读 来源:Dev.to

Neander has no exceptions. No try , no catch , no finally . A call to one of the host application's APIs returns something closer to Rust's Result : either the answer, or the reason there is no answer. In place of a catch block there is one type marker, three operators, and a guarantee that every submission comes back in the same shape no matter what happened. Last time the foundational series closed with isolation. This is the first of two encores, and it takes the subject that came up in nearly every entry without ever being laid out in full: what happens when something goes wrong. There are two answers, because there are two audiences. An error is a value while the program runs, and a verdict once it has stopped. The two are made of the same parts, on purpose. The failable type Every call returns a failable type, written T! . It carries either a value of type T or an error with a code, a message, and the name of the function that produced it. T! is the mirror of the nullable type T? . Same shape, different question: one asks whether a value is there at all, the other asks whether obtaining it worked. The mirroring runs deeper than the notation, because the same three operators serve both types. A failure gets no unwrapping vocabulary of its own. Those three are =? , ?? and is : // narrow, or throw the error out of the enclosing block let order : Order =? call orders .get ( id : 42 ) // or substitute a default let order : Order = call orders .get ( id : 42 ) ?? emptyOrder // or inspect it and decide let result : Order! = call orders .get ( id : 42 ) if result is error { if errorCode ( result ) != 404 { throw result } return emptyOrder } A standalone call statement, one without a let , narrows implicitly: the error is thrown and the success value is discarded. One property does the heavy lifting throughout the rest of this post: T! originates only from a call . No expression picks up a ! along the way, and no widening rule introduces one. The marker means exactly o

本文内容来源于互联网,版权归原作者所有
查看原文