c# - Difference between throw new Exception with no surrounding catch and putting this in a catch? -
what difference (if any) in writing:
if (file.exists(filepath)) //something else throw new filenotfoundexception(); and surrounding if/else block, above, in try brace catch.
in fact, catch needed? if so, catch? or perhaps better comparison put if part of above block in try brace (without if statement) , catch filenotfoundexception, throwing call stack (throw).
thanks
by surrounding if block try catch means going have handle missing file there , in catch (see @lukas's answer). if going handle missing file in code, don't need else-throw, because know file missing first if. on other hand, if want calling code (somewhere higher call stack) handle missing file, passing information on in exception ok, don't want go wrap throw in try-catch because won't thrown out of block of code.
Comments
Post a Comment