Asking a Generic Method to Throw Specific Exception Type on FAIL

前端 未结 5 987
深忆病人
深忆病人 2021-02-08 06:32

Right, I know I am totally going to look an idiot with this one, but my brain is just not kicking in to gear this morning.

I want to have a method where I can sa

5条回答
  •  天涯浪人
    2021-02-08 07:21

    I have been instantiating inline the type of exception I want to throw, like this:

    if (ItemNameIsValid(ItemName, out errorMessage))
        throw new KeyNotFoundException("Invalid name '" + ItemName + "': " + errorMessage);
    if (null == MyArgument)
        throw new ArgumentNullException("MyArgument is null");
    

提交回复
热议问题