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 argumentexceptions 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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -