<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 4 August 2014 17:21, Jacob Carlborg via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Monday, 4 August 2014 at 04:09:07 UTC, Manu via Digitalmars-d wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Almost all exceptions I throw are in relation to bad input data, and they<br>
are to be caught at a slightly higher level of input processing. My code<br>
has become try/catch-tastic, and I really don't like looking at it.<br>
</blockquote>
<br></div>
Why does it matter it has a lot of try/catch-blocks.</blockquote><div><br></div><div>I hate pointless brace and indentation spam, I feel it severely damages the readability of my code. And try/catch has a natural tendency to produce horrid nested structures.</div>
<div>I would rather C-style error reporting via sentinel values and 'if()' than try/catch in practically every case imaginable, especially when try/catches start to nest themselves.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It rather sickens me and reminds me of Java<br>
</blockquote>
<br></div>
So just because your code looks like Java you want to come up with a new feature that is exactly like "catch", but with a new name. Instead your code will become scope-tastic (whatever that means) and it doesn't look like Java because it use a different keyword.</blockquote>
<div><br></div><div>Okay, so why are scope guards such a key talking point in D if people loved try/catch?</div><div>'scope-tastic' code would be flat and sequential. I find flat and sequential code MUCH easier to reason about. Again, why would anyone care about 'scope' if they didn't feel this way at some level?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
, and I'm strongly tempted to just<br>
abandon my experiment and return to C-style error handling with sentinel<br>
values.<br>
</blockquote>
<br></div>
I can't see how that will improve anything. Seems like you have some grudge against Java and don't won't your code to look like it.</blockquote><div><br></div><div>It will produce flat sequential code which is easier to follow.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So... why not make scope guards more useful? It wouldn't be hard.<br>
scope(failure, MyException e) is completely non-destructive, and adds<br>
significant power to the concept.<br>
</blockquote>
<br></div>
I think it's better to support catch-blocks without a try-block. BTW, if I recall correctly, I have already proposed this and it was turned down.</blockquote><div><br></div><div>I agree, I had the same thought. But I felt it was better to integrate it into an existing (and popular) structure than to form a new one.</div>
<div>I actually think there would be a valuable place for both though.</div></div></div></div>