You don't really provide enough information to answer your question. The obvious answer is to look at the message of the exception, but I'm guessing that isn't what you're looking for.
If it's truly important that you be able to tell them apart programatically, then use another exception, or at least use the paramName
property of the current exception's constructor. That will give you somewhat more relevant information.
However, using your own exception type is the only way to guarantee that you're catching the exception for a particular circumstance. Because ArgumentException
is part of the framework, it's possible that something else that you call might throw it, which would lead you into the same catch block. If you create your own exception type (either one for both or one for each of the scenarios), this will provide you with a way to handle the specific error. Of course, judging by your example, it seems like it would be simpler just to check and see if Val1
or Val2
is null before you call the function to begin with.