On 09/02/14 14:05 , Dicebot wrote:

You should have been probably already aware of this, but just in case:
http://forum.dlang.org/post/ftakrucgtfcicfbkzwbs@forum.dlang.org

Hello, i wanted since a long time to ask about this (as a not
experienced developer) if there is a suggested way for dealing with
exceptions as i am a bit confused with the d language documentation and
vibe.d examples i can find.
Especially when exceptions are being used for validations, database
queries and other parts that are actually part of the normal flow of the
program and need to display their messages to users . It is getting a
bit blurred the border of using them as conditionals or actual errors
(Errors are exceptional, unusual, and unexpected) because a wrong email
input is not unusual at all.

Here for example in the login function those exceptions will be thrown
thousands of times in a popular website:
userman / source / userman / web.d

try {
user = m_controller.getUserByEmailOrName(username);
enforce(user.active, "The account is not yet activated.");
enforce(testSimplePasswordHash(user.auth.passwordHash, password),
"The password you entered is not correct.");

auto session = req.session;
if (!session) session = res.startSession();
session["userEmail"] = user.email;
session["userName"] = user.name;
session["userFullName"] = user.fullName;
res.redirect(prdct ? prdct : m_prefix);
} catch( Exception e ){
logDebug("Error logging in: %s", e.toString());
string error = e.msg;
string redirect = prdct ?
prdct : "";
res.renderCompat!("userman.login.dt",
HTTPServerRequest, "req",
string, "error",
string, "redirect",
UserManSettings, "settings")(req, error, redirect,
m_controller.settings);
}

I read the above conversation but despite performance and suggestions
for improvement i was wondering if there is a recommended way to deal
with that (with current state of D and vibe.d). Let's say a summarized
advice for new users. Is this function the way to go or it would be
better to keep exceptions for exceptional situations? Or is it that the
answer is still ambiguous because of different reasons and priorities
(clear code, performance etc)?