c# - Including paramaters only for the purpose of exception reporting in inner functions -


createdocument(string templatepath) {     document doc = opendocument(templatepath);     picture pic = getlogo();     addlogo(doc, pic, templatepath); }  addlogo(document doc, picture logo, string templatepath) {     picture placeholder = doc.findlogoplaceholder();     if (placeholder.size != logo.size)     {         throw new applicationexception(             string.format("invalid template {0}, logo size: {1}, required: {2}",                  templatepath, placeholder.size, logo.size             ));     } } 

consider above code example made up.

notice reason templatepath passed addlogo method facilitate exception generation.

i have in code today needed this, , feels nasty code smell me. i'm not familiar exception handling patterns , don't see better way it.

i'm wondering thoughts , if there better pattern dealing situations this.

create exception on higher level:

createdocument(string templatepath) {     document doc = opendocument(templatepath);     picture pic = getlogo();     try {         addlogo(doc, pic);     } catch (invalidlogosize e) {         throw new applicationexception(             string.format("invalid template {0}, logo size: {1}, required: {2}",                  templatepath, e.psize, e.lsize             ));     } }  addlogo(document doc, picture logo) {     picture placeholder = doc.findlogoplaceholder();     if (placeholder.size != logo.size)     {         throw new invalidlogosizeexception(placeholder.size, logo.size);     } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -