c# - How to filter out catch blocks -


i need return false prevent logging if sp.serverexception has been thrown. in other cases need logging , return false too.

try {     folder = getfolderbyrelativeurl(folderrelativepath); } catch (sp.serverexception serverex) {     //if file not found logging not need     if (serverex?.message == "file not found")     {         return false;     }     //how can go here } catch (exception ex) {     //to there     log(ex.message);     return false; } 

i know solution be

try {     folder = getfolderbyrelativeurl(folderrelativepath); } catch (exception ex) {     //if file not found logging not need     if (!(ex sp.serverexception && ex?.message == "file not found"))     {         log(ex.message);     }      return false; } 

try when keyword:

try {     folder = getfolderbyrelativeurl(folderrelativepath); } catch (sp.serverexception serverex) when (serverex.message == "file not found") {    return false; } catch (exception ex) {     //to there     log(ex.message);     return false; } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -