News for hackers. Stuff that matters.
Re:Effective Rust by gpm on Thursday June 15, 2023 @01:32PM (#36343919)
assert!(cond) in rust is basically

    if !cond {
        // I ad-libbed the exact error message
        panic!("Asssertion failed {cond} was false, line/file information, etc")
    }
panic!(message) is "either throw an exception containing message, or print the message + maybe a backtrace and abort the process".

You can use compiler flags to guarantee that it aborts instead of throwing an exception, you can't use compiler flags to guarantee that it acts an exception, sometimes rust will just abort the process (for example if you panic!() while you're already unwinding because of a prior panic!()).

If nothing catches the exception (and that's usually the case, by convention), the runtime will print the message, maybe a backtrace, and kill the thread that paniced.

There are no comments on this comment yet.