c# - ArgumentException not working -
is there reason why argumentexception might not work?
when moved our solutions .net 4.0, cannot use argumentexception.
string nodata = '--no data--' try { instanceid = microsoft.xlangs.core.service.rootservice.instanceid.tostring(); } catch (argumentexception) { instanceid = nodata; }
when use exception class instead of argumentexception, can pass variable nodata instanceid.
catch (exception e) { instanceid = nodata; }
the error encountering when
object reference not set instance object.
the problem doing in code catching argumentexception
s whereas before caught exceptions - exceptions derive exception
fit old catch
criteria.
if want catch specific exception (nullreference
) need catch correct 1 (not argumentexception
). change following:
catch (nullreferenceexception) { instanceid = nodata; }
but if don't have specific behavior nullreferenceexception
i'd keep it:
catch (exception) { instanceid = nodata; }
read msdn better understand catching specific types of exceptions
Comments
Post a Comment