3 ms·
> Not providing any value judgement but… this seems completely irrelevant to the topic. Rust has long-settled on not exceptions, and they are largely incompatib
by vbezhenar 6y ago
> Not providing any value judgement but… this seems completely irrelevant to the topic. Rust has long-settled on not exceptions, and they are largely incompatible with the language's stated goals and purpose.
I think that it's possible to build a bridge from Result to panics, thus allowing a developer to choose a particular style of error-handling. I don't understand why exceptions are incompatible with language stated goals.
> Except for the part where their very existence is optional.
But that's up to developer to decide, right? By default panics do work. If I want to call `abort()` on panic, I have to explicitly configure it.
> You mean like `Result::unwrap` which has existed since before Rust 1.0 was a thing?
Yes, but with improved panics (including hierarchy of panics, capturing stacktrace) and enhanced language syntax to better integrate that model into a language, rather than discouraging people from using it.
- steveklabnik 6y ago> But that's up to developer to decide, right? By default panics do work. If I want to call `abort()` on panic, I have to explicitly configure it. Yes and no. If you need either semantic, you need to specify it, so that when others use your code, they ensure they don't get something that's broken. They "work by default" in the sense that that's the default behavior, but people don't rely on it because unless you say you require it, they may use your code without them.
- vbezhenar 6y agoI guess, you're talking about library code. Libraries should use Result on their API boundaries, that's for sure. If library internals wants to use exceptions-panics, I think that language should allow it, because that's an implementation detail and compiler should allow modules with different panic configurations to co-exist (for example library can use unwinding panic, but as soon as it leaves library boundary, application will abort if it's configured to abort on panic). If it's not possible to implement in a sane way, then I'm OK with libraries forced to use Results as the only error-handling strategy, because I'm more concerned about program code.
- steveklabnik 6y agoIn a systems language, implementation details matter :) You may be compiling with panic=abort because you do not have a useful unwinding implementation, and so a library cannot depend on it existing, even if it's only internal to the library.
- masklinn 6y ago> You may be compiling with panic=abort because you do not have a useful unwinding implementation, and so a library cannot depend on it existing, even if it's only internal to the library. panic=abort is also a somewhat commonly suggested way of slimming down binaries.
- deleted 6y ago[deleted]
- masklinn 6y ago> I think that it's possible to build a bridge from Result to panics, thus allowing a developer to choose a particular style of error-handling. I don't understand why exceptions are incompatible with language stated goals. Because they require significant runtime support. > But that's up to developer to decide, right? By default panics do work. If I want to call `abort()` on panic, I have to explicitly configure it. Not necessarily. It's the user of a library which decides whether they allow panics or not, so libraries can not assume panics will be available at all. > Yes, but with improved panics (including hierarchy of panics, capturing stacktrace) panics already capture stacktraces (if you run with the proper envvar enabled). As to hierarchies of panics… how do you propose to do that in a language without inheritance? Adding inheritance? > and enhanced language syntax to better integrate that model into a language, rather than discouraging people from using it. But the language should discourage people from using it. Having multiple ways of doing errors is actively bad, especially when one of them is completely unnecessary and plain doesn't work in many environment.