In fact, you do not provide enough information to answer your question. The obvious answer is to look at the exception message, but I assume this is not what you are looking for.
If it is really important that you can separate them programmatically, use another exception, or at least use the paramName property for the current exception constructor. This will give you some more relevant information.
However , using your own type of exception is the only way to ensure that you catch an exception for a particular circumstance . Since ArgumentException is part of the framework, it is possible that something else that you are throwing can throw it, which will lead you to the same catch block. If you create your own type of exception (one for both or one for each scenario), this will provide you with a way to handle a specific error. Of course, judging by your example, it seems that it would be easier to just check if Val1 or Val2 is null before you call the function to start.
Adam robinson
source share