Friday 15 February 2013

function - Name of design pattern for method which does nothing but throw an exception upon a condition? -



function - Name of design pattern for method which does nothing but throw an exception upon a condition? -

i've came across code functions nil except check conditional , throw exception or nil depending on outcome of evaluation of conditional.

the code this:

class="lang-cs prettyprint-override">public string mymethod() { var name = "foo"; ensuresuccess(name); homecoming name; } // throws exception if name not "bar" public void ensuresuccess(string name) { if (name != "bar") { throw new argumentexception("not bar!"); } }

what called? named design pattern?

also considered practice or bad practice?

example of code in wild uses ensuresuccessstatuscode method in httpresponsemessage.cs part of system.net.http microsoft. (code, documentation)

that's not design pattern. it's called programming assertion.

in computer programming, assertion predicate (a true–false statement) placed in programme indicate developer thinks predicate true @ place. if assertion evaluates false @ run-time, assertion failure results, typically causes execution abort.

function exception design-patterns methods

No comments:

Post a Comment