4 ms·
To do so in C# requires messing with C libraries, but generally most behaviour that could actually segfault throws an exception instead.
by Deukhoofd 5y ago
To do so in C# requires messing with C libraries, but generally most behaviour that could actually segfault throws an exception instead.
- garaetjjte 5y agopanic is just different name for exception though.
- throwawayninja 5y agoExceptions can be handled, so in rust an "exception" is a "Result<T,U>". A panic means the program terminates, guaranteed. This allows us to ignore hugely difficult edge cases when interacting with hardware / OSes and still ensure the code meets safety guarantees; if the code isn't executing it cannot invalidate any invariants.
- baseballdork 5y ago> A panic means the program terminates, guaranteed. That's not strictly true: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
- adastra22 5y agoPanic is what Rust calls exceptions.
- dragonwriter 5y ago> Panic is what Rust calls exceptions. Not exactly; “panic” is what Go calls exceptions. Rust “panic!” macro, though, is more of a gentle abort (I guess it's like an uncatchable exception, but that qualifier so radically changes the nature that I can't see it as really the same kind of thing.)
- adastra22 5y agohttps://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
- xanathar 5y agoPopping in my mind: - System.Diagnostics.Debug.Assert (on debug builds) - Envinroment.FailFast (this is precisely what panic! is usually used for) - void BlowUp() { BlowUp(); } But, in reality, any unexpected Exception: how would you properly handle an unexpected NRE or index out of bounds? Either swallowing the exception (bad) or aborting.