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
Post a Comment