c# - Return value from a method if the method throws an exception -


it's monday again , have question c# basics. happens return value method if method throws exception?

specifically, happening "under hood" when exception being thrown inside method , effect have on return value? in situation, how return value calculated internally?

let's there 2 scenarios: 1 return value of type int , of type object. default(t) going called internally when exception occurs? in such case, should consider return value of type int 0 while return value object null?

the short, oversimplified answer it won't return anything. code "breaks" wherever exception occurs , goes down stack until catches it.

even if do happen catch exception, variable tried initialize method's return value remain before method called:

var = 5;  try {     = mymethodthatthrowsanexception(); } catch {     // @ point, variable still equals 5. } 

i should mention shouldn't feel concerned function's return value if throws exception. if do, you're doing wrong, using exceptions flow control.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -