Asking a Generic Method to Throw Specific Exception Type on FAIL

前端 未结 5 979
深忆病人
深忆病人 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:11

    Have you tried, instead:

    static T TestException(string message)
    {}
    

    because I have a feeling that putting in the generic constraint is not necessary as all throwable exceptions must inherit from System.Exception anyway.

    Remember that generics do accept inherited types.

提交回复
热议问题