Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
April 27, 2014 Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
So I have this procedure: extern (C) void signal_proc(int sn) @system nothrow Which can call this: shutdown_system() @system nothrow Problem I have is inside "shutdown_system()" I have code that can't possibly be @nothrow because their are a lot of subsystems to shutdown. What I've done for now is just strip the @nothrow attribute of the C function in core.stdc.signal. It feels very hackish but it works.. |
April 27, 2014 Re: Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Damian Day | On 04/26/2014 06:39 PM, Damian Day wrote: > Problem I have is inside "shutdown_system()" I have code that can't > possibly be @nothrow because their are a lot of subsystems to shutdown. You can wrap the contents of shutdown_system() with a try-catch block and swallow all exceptions that way. Ali |
April 27, 2014 Re: Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Sunday, 27 April 2014 at 01:53:15 UTC, Ali Çehreli wrote:
> On 04/26/2014 06:39 PM, Damian Day wrote:
>
> > Problem I have is inside "shutdown_system()" I have code that
> can't
> > possibly be @nothrow because their are a lot of subsystems to
> shutdown.
>
> You can wrap the contents of shutdown_system() with a try-catch block and swallow all exceptions that way.
>
> Ali
Oh right, didn't realize it would be that simple. Thank you!!
|
April 27, 2014 Re: Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Damian Day | On 4/26/14, 6:39 PM, Damian Day via Digitalmars-d-learn wrote:
> So I have this procedure:
> extern (C) void signal_proc(int sn) @system nothrow
> Which can call this:
> shutdown_system() @system nothrow
>
> Problem I have is inside "shutdown_system()" I have code that can't
> possibly be @nothrow because their are a lot of subsystems to shutdown.
>
> What I've done for now is just strip the @nothrow attribute of the C function in
> core.stdc.signal. It feels very hackish but it works..
Careful here.. it sounds like you're doing work inside a signal handler that's likely to be unsafe / undefined. There's very very little that you can safely do inside a signal handler. Hit google and search for async signal safe.
|
April 27, 2014 Re: Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Damian Day | On 4/27/14, Damian Day via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > So I have this procedure. Have a look at std.exception.assumeWontThrow: http://dlang.org/phobos/std_exception.html#.assumeWontThrow |
April 27, 2014 Re: Can I circumvent nothrow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sunday, 27 April 2014 at 08:04:54 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote:
> On 4/27/14, Damian Day via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>> So I have this procedure.
>
> Have a look at std.exception.assumeWontThrow:
> http://dlang.org/phobos/std_exception.html#.assumeWontThrow
Keep in mind that "assume won't throw" will assert *should* an exception actually be thrown.
If the function actually can and will throw, but you simply don't care, you'd need a "squelchException" (which we don't have), or more simply, just:
//----
try {
myCode();
} catch (Exception){}
//----
|
Copyright © 1999-2021 by the D Language Foundation