Hacker News new | past | comments | ask | show | jobs | submit login

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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: