[go: up one dir, main page]

|
|
Log in / Subscribe / Register

Why the controversy?

Why the controversy?

Posted Sep 24, 2024 10:46 UTC (Tue) by roc (subscriber, #30627)
In reply to: Why the controversy? by dirklwn
Parent article: Best practices for error handling in kernel Rust

That "Error: 22" message is printed when the `main` function returns an error. It has nothing to do with the ? operator and nothing do with with kernel vs user space.


to post comments

Why the controversy?

Posted Sep 24, 2024 11:36 UTC (Tue) by Wol (subscriber, #4433) [Link] (1 responses)

Isn't all this just missing the point?

The point as I understand it is that adding a "throw error" deep in the call stack will cause the compiler to object blue murder unless that error is explicitly handled.

Yes you can just add a question mark in the caller routine to say "punt this error up the stack".

But as soon as somebody starts digging through the patches to debug a problem, the fact that "git diff" or whatever shows that "somebody added a ? to this subroutine call", red flags will start going up everywhere.

So the naive C way of just ignoring the error is impossible. You can handle the error deep in the bowels. You can propagate it up the stack with the ? Either way you're forced to do *something* rather than leaving it behind as a landmine for the next programmer. That's the important point - the compiler won't let you do anything else. (And there's no difference between user space and kernel space in this regard - nor should there be.)

And all that stuff about main not having a ? is just coding standards to say "don't let the entire program punt it back up to the command-line / xterm / konsole / whatever to handle/drop aka terminate with an unacknowledged error.

Cheers,
Wol

Why the controversy?

Posted Sep 24, 2024 20:53 UTC (Tue) by roc (subscriber, #30627) [Link]

Yes, that's right.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds