Q: Exception design questions
Daniel Keep
daniel.keep.lists at gmail.com
Sat Jun 16 05:52:11 PDT 2007
Henning Hasemann wrote:
> why exactly do you use this pattern? Why not
>
> auto ex = new SqlProgrammingException("text");
> with(ex) {
> setSql(operation);
> setProperty("ValueRow", i);
> setProperty("ValueType", t);
> }
> throw ex;
>
> Ok that are 2 additional lines and a temporary variable but that
> shouldnt be a problem, or?
>
> Henning
I suspect he uses it *because* it's shorter and avoids the temporary
variable. :P If I didn't hate member call chaining so much, I'd
probably be tempted to do the same; using with makes the code a bit
unwieldy.
Not terribly constructive, but wouldn't it be nice if D had
statements-as-expressions? Then it would simplify to:
throw with(new SqlProgrammingException("text")) {
setSql(operation);
setProperty("ValueRow", i);
setProperty("ValueType", t);
}
One line longer for the closing brace, but removes the need for both the
temporary and the chained function call.
It's not going to happen, but we can dream, right? :P
-- Daniel
More information about the Digitalmars-d
mailing list