This project is read-only.
1
Vote

A way to state what exceptions a delegate passed as a parameter can throw

description

Given the following method:
    public static void DoAction(Action action)
    {
        action();
    }
Exceptional is telling me that an exception System.Exception should be documented because action may throw anything. However, suppose I know that Action will only throw System.IOException - can there be some way to tell Exceptional that that is the case, and that only the IOException needs to be documented in DoAction?

It seems to me that a good way to do this could be with attributes:
    public static void DoAction([Throws(typeof(System.IOException))] Action action)
    {
        action();
    }
Similarly, if I know it won't throw anything, it could be either one of:
    public static void DoAction([Throws] Action action) // Empty attribute parameter list

    public static void DoAction([NoThrow] Action action)
Although I realise that this would require a NuGet package or something in addition to the resharper plugin.