www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can I circumvent nothrow?

reply "Damian Day" <damianroyday gmail.com> writes:
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..
Apr 26 2014
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Apr 26 2014
parent "Damian Day" <damianroyday gmail.com> writes:
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!!
Apr 26 2014
prev sibling next sibling parent Brad Roberts via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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.
Apr 26 2014
prev sibling parent reply Andrej Mitrovic via Digitalmars-d-learn writes:
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:
Apr 27 2014
parent "monarch_dodra" <monarchdodra gmail.com> writes:
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:
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){} //----
Apr 27 2014