zlacker

[parent] [thread] 7 comments
1. Velila+(OP)[view] [source] 2022-10-02 16:15:56
I think I prefer Rust's way of doing things. Just last night I used the Vec! macro incorrectly putting in a comma instead of a semi-colon and despite the program compiling correctly, it immediately panicked with an OOB error. With C it would have been a lot harder to even notice a bug little alone track it down.
replies(1): >>layer8+i1
2. layer8+i1[view] [source] 2022-10-02 16:23:09
>>Velila+(OP)
Right. My personal opinion is that exceptions provide a better trade-off between catching bugs and still allowing the chance of graceful shutdown or recovery.
replies(2): >>Velila+K3 >>stjohn+mv
◧◩
3. Velila+K3[view] [source] [discussion] 2022-10-02 16:33:37
>>layer8+i1
In my case it wouldn't have raised an exception though, it would have just been UB.

It's not like there's not exceptions in Rust though. The error handling is thorough to a fault when it's used. Unwrap is just a shortcut to say "I know there might be bad input, I don't want to handle it right now, just let me do it and I'll accept the panic."

replies(1): >>layer8+36
◧◩◪
4. layer8+36[view] [source] [discussion] 2022-10-02 16:45:39
>>Velila+K3
By exceptions, I’m referring to languages with exceptions as a dedicated language construct with automatic stack unwinding, and preferably without UB (e.g. Java or C#). Rust doesn’t have exceptions in that sense.
replies(1): >>dureui+nj
◧◩◪◨
5. dureui+nj[view] [source] [discussion] 2022-10-02 17:58:15
>>layer8+36
But panics in rust are pretty much exceptions though?

The differences are they are actually meant to be used for exceptional situations ("assert violated => there's a bug in this program" or "out of memory, catastrophic runtime situation") and they are not typed (rather, the panic holds a type erased payload).

Other than that, it performs unwinding without UB, and is catchable[0]. I'm not seeing the technical difference?

[0]: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html

replies(1): >>layer8+Ql
◧◩◪◨⬒
6. layer8+Ql[view] [source] [discussion] 2022-10-02 18:13:46
>>dureui+nj
You’re probably right now that I’ve read up on it, I wasn’t previously aware of catch_unwind.
replies(1): >>dureui+Jm
◧◩◪◨⬒⬓
7. dureui+Jm[view] [source] [discussion] 2022-10-02 18:18:57
>>layer8+Ql
Glad to be of service. Note that the idiomatic error handling in rust is still Result based rather than panic/catch_unwind based.

Nevertheless a long living application like, e.g., a webserver will catch panics coming from its subtasks (e.g., its request handlers) via catch_unwind

◧◩
8. stjohn+mv[view] [source] [discussion] 2022-10-02 19:14:47
>>layer8+i1
exceptions would be awful in the kernel. I would be highly surprised if kernels like fuscia allow c++ exceptions.
[go to top]