[Issue 3462] New: Add a clean way to exit a process.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 31 21:46:11 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3462

           Summary: Add a clean way to exit a process.
           Product: D
           Version: 2.035
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P2
         Component: druntime
        AssignedTo: sean at invisibleduck.org
        ReportedBy: llucax at gmail.com


--- Comment #0 from Leandro Lucarella <llucax at gmail.com> 2009-10-31 21:46:07 PDT ---
Created an attachment (id=485)
druntime patch (against svn r185)

Maybe I'm missing something, but I can't find any "standard" way to exit a
program cleanly. I can't just call C's exit() function because the stack
doesn't get unwinded so scope guards and other finally blocks are not executed.
This is bad if you want to do some cleanup. In my particular case, I create a
lock file so other instances of a program exit immediately if the lock file is
present, and I want to remove the lock file as soon as the program finishes. I
want to be able to call some exit() function in any part of the program for
simplicity though.

I hacked a solution by adding all the program inside a try block, catching an
special "Exit" exception with a status attribute. If that exception is catched,
the program returns the exception's status code.

I think this is an useful feature that deserves being in the standard library,
and for that we need runtime support (that's why I added it to the druntime
component instead of Phobos, even when Phobos should be hacked too.

Attached are patches for druntime and phobos with this changes:

druntime:
* Add a ProcessExit class to core.exception module (inherits from Object since
it's not a real exception and we don't want people catching it even when doing
a catch (Throwable)).
* Catch the new exception in tryExec() nested funtion from dmain2.d, even when
rt_trapExceptions is false (again, because is not really an exception), making
the status attribute the new program's exit code.

phobos:
* Add a new void std.process.exit(int status). All it does is "throw new
ProcessExit(status);" to hide implementation details.

I don't know if std.process is the better module, maybe it should go somewhere
else.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list