www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Questions about the scope/Exception machinery

reply "Qox" <robertw89 googlemail.com> writes:
Hello dear D fellows :D,

The problem boils down to this.

I try to write a Software which should be as compact as possible.
This means that i don't like to use any exception handling (which
appears to be hardly integrated into the language, not that good
for demoscene/OS dev stuff).
So i ran into the first issue, scope expressions.

When i write

       scope(exit) foo();

it seems that it generates exception ahndling code. Is this the
case even if the called function and the callee are both nothrow
decorated? Can i force the compiler to generate goto code instead
of the exception handling stuff?
May 27 2014
parent reply "Qox" <robertw89 googlemail.com> writes:
ok I found a old thread about it, just delete this thread please
May 27 2014
next sibling parent reply Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
Dne Tue, 27 May 2014 14:02:04 +0200 Qox via Digitalmars-d  
<digitalmars-d puremagic.com> napsal(a):

 ok I found a old thread about it, just delete this thread please
This is mail list so it is not possible to delete thread. Btw, can you post link to the thread which you find.
May 27 2014
next sibling parent "Qox" <robertw89 googlemail.com> writes:
The thread is

http://forum.dlang.org/thread/dtcxszysceiopzwewrpk forum.dlang.org?page=1
Title "scope(exit) without exception handling?"
May 27 2014
prev sibling parent Mike Parker <aldacron gmail.com> writes:
On 5/27/2014 9:07 PM, Daniel Kozak via Digitalmars-d wrote:
 Dne Tue, 27 May 2014 14:02:04 +0200 Qox via Digitalmars-d
 <digitalmars-d puremagic.com> napsal(a):

 ok I found a old thread about it, just delete this thread please
This is mail list so it is not possible to delete thread. Btw, can you post link to the thread which you find.
Actually, it's a newsgroup server :)
May 27 2014
prev sibling parent reply "Qox" <robertw89 googlemail.com> writes:
nothrow doesn't seem to work with the recent dmd compiler :(
I know it because _d_local_unwind2() is still called.

Seems as if I need another more ugly (but still nicer than C++) 
solution. Mixins which jump on an error to a label...hell I love 
low level languages (Java is in this sense crap because they 
disallow [usefull] constructs like goto, templates, ...)

the code will look like this (usage)

  mixin(onError(condition, "handling0", "handlingCallback", 
parameter0, parameter1));

the CTFE function onError checks the condition, if it is false it 
copies the parameters into variables and jumps to the label named 
after handling0.

on the end of the function there will be

  mixin(errorHandling("cast(int)0", ["handling0", 
"handlingCallback", ...]));

which writes the goto labels, handling code etc which looks like 
this

  label_handleFoo:
  handleFoo();
  label_handling0:
  handlingCallback(handling0_parameter0, handling0_parameter1);
  return cast(int)0;

a bit ugly but not so ugly as C++ ... any better ideas?
May 27 2014
next sibling parent "Qox" <robertw89 googlemail.com> writes:
Ofcourse this doesn't look that maintainable to me...well, then 
the C++ struct destructor way???
May 27 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 5/27/2014 9:43 PM, Qox wrote:
 nothrow doesn't seem to work with the recent dmd compiler :(
 I know it because _d_local_unwind2() is still called.
notrhow doesn't turn off exception handling. It just doesn't allow you to throw from a particular function. From inside a nothrow function, you can still call functions that throw, but you have to wrap them in try..catch blocks and swallow any exceptions that *are* thrown.
May 27 2014
parent reply "Qox" <robertw89 googlemail.com> writes:
sounds a bit like C++ handling to me, for me *personally* it 
misses also the point about nothrow, because it gurantues 
nothing...which is like in C++ and imho bad...
May 27 2014
parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 27 May 2014 at 13:24:08 UTC, Qox wrote:
 sounds a bit like C++ handling to me, for me *personally* it 
 misses also the point about nothrow, because it gurantues 
 nothing...which is like in C++ and imho bad...
It guarantees at compile time that your function will not throw an Exception.
May 27 2014