top | item 28095327

(no title)

danielparks | 4 years ago

He posted a follow up about error handling in Zig that I thought was interesting: https://ayende.com/blog/194466-A/looking-into-odin-and-zig-m...

I’ve seen the “clean up errors yourself” argument before, but, like the author, I don’t think it holds water. Often the correct response to errors is to panic() or pass it up the stack so the caller can deal with it or—more likely—panic() itself.

discuss

order

Zababa|4 years ago

I think it's nice to have two mechanisms for errors like in ML: sum types for errors that the calling function can realistically recover from, and exceptions for the rest.

dnautics|4 years ago

You can do that in zig with @panic and even convert from sum type error to an irrecoverable exception: `catch @panic("oops");`

Gaelan|4 years ago

This is Rust's approach, too: realistically recoverable errors are handled with Result<T, E>, and other are handled through panics. (Panics are generally implemented as exceptions, i.e. they unwind the stack, but the compiler can also be configured to make them just abort.)

randyrand|4 years ago

C has always had Asserts for that reason.

tored|4 years ago

I agree with the author that errdefer seems like the winning feature of zig. Proper error handling is the most important part of any language or system.

Unfortunately most common languages does not prioritize this. As a contractor I have dug myself thru a lot of awful code in different languages and the most common denominator is improper error handling.

ksec|4 years ago

Off Topic:

>He posted a follow up about error handling......

When I was reading the original blog I was thinking if he had any follow up, so I decide to click on archive and the homepage. And this article, somehow doesn't show up in both list. As a matter of fact I couldn't even find how to get to this blog post without your direct linking. Then it turns out it is a "FUTURE POSTS".

How does that work and why? Is this suppose to be some sort of preview before it is officially published?

ayende|4 years ago

Author here - I typically just throw things into the post queue and they drop every day. In this case, I replied to a question and it turned into a full blown post.

danielparks|4 years ago

Yeah, it’s weird. I tried stripping the key= parameter from the link when I commented, but it’s required.

The author posted the link in the comments of the original post.

randyrand|4 years ago

I dont panic nearly as much as you it seems!

Handling Errors causes us developers so confusion, because we are so used to exceptions and how poorly they were conceived.

Errors should be called Failures. It's just when a function fails to so what it says it does. Nothing more, nothing special about it!

If you call fopen() and it doesn't find the file, that's a Failure! No reason to panic! Just go create the file!