i'm trying cater error in data access layer, return int of value -1. see below:
protected void folderbtn_click(object sender, eventargs e) { if (page.isvalid) { try { docsdalc dalc = new docsdalc(); // updating 2 tables here - folders , folderaccess tables // - ado.net transaction int folderid = dalc.createfolder(...); if (folderid > 0) { response.redirect(request.url.tostring(), false); // re-construct include newly-created folderid } else { // how throw error here? } } catch (exception ex) { handleerrors(ex); } } } if data layer returns -1, how can throw error within try block?
as following - however, since catching errors, if know it's problem, better call overload of handleerrors method pass in string defining problem, rather throw exception (which costly do).
if still want throw exception:
if (folderid > 0) { response.redirect(request.url.tostring(), false); // re-construct include newly-created folderid } else { throw new exception("database returned -1 createfolder method"); } a possible alternative:
if (folderid > 0) { response.redirect(request.url.tostring(), false); // re-construct include newly-created folderid } else { handleerrors("database returned -1 createfolder method"); } with of course overloaded handleerrors method.
Comments
Post a Comment