3 ms·
`panic` isn’t really an error that you have to (or can) handle, it’s for unrecoverable errors. Sort of like C++ assertions. Also there is the no_panic crate, w
by arijun 1y ago
`panic` isn’t really an error that you have to (or can) handle, it’s for unrecoverable errors. Sort of like C++ assertions.
Also there is the no_panic crate, which uses macros to require the compiler to prove that a given function cannot panic.
- nicce 1y agoI would say that Segmentation Fault is better comparison with C++ :-D
- marcosdumay 1y agoWell, kinda. It's more similar to RuntimeException in Java, in that there are times where you do actually want to catch and recover from them. But on those places, you better know exactly what you are doing.
- josephg 1y agoYou can handle panics. It’s for unrecoverable errors, but internally it does stack unwinding by default like exceptions in C++. You see this whenever you use cargo test. If a single test panics, it doesn’t abort the whole program. The panic is “caught”. It still runs all the other tests and reports the failure.
- swiftcoder 1y ago> but internally it does stack unwinding by default Although as a library vendor, you kind have to assume your library could be compiled into an app configured with panic=abort, in which case it will not do that