Skip to content

Add a way to exit a thread early and run destructors, akin to panic!(), without displaying an error message to the user #1089

Closed
@yberreby

Description

@yberreby

Unwinding the stack and running destructors is useful to abort a particular thread, without having to add early returns all the way up the call stack. panic!() provides this functionality, but also displays a message to the user, even if the panic is caught, which is disturbing: you don't want to expose debugging info such as line number to the end user.

This would provide a clean exit mechanism while avoiding adding functionality that's already there, as you get (correct me if I'm wrong) similar results with either early returns and panic!(): the stack unwinds, destructors are run, and the thread exits cleanly. This is not a problem for single-threaded programs, which can use std::process::exit and let the OS clean up resources, but would be useful for multi-threaded programs.

Essentially, I'm proposing a silent version of panic!(), that does not actually panic (does not change the return value of http://doc.rust-lang.org/1.0.0-beta.2/std/thread/fn.panicking.html , for example), but acts as if all currently called functions returned early. Being able to panic!() without cluttering logs would probably also be useful.

EDIT: actually, a silent version of panic!() would be simpler to implement and probably better overall (avoid having separate panic mechanisms, as pointed by @Diggsey)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions