Adding it in the summary is good for documentation and communication with other developers.
You said you want to have a more formal way, tough.
From what I know of C# (very little), Exception
has two main child classes, ApplicationException
and SystemException
. You generally can't guarantee that a system exception won't be thrown. We may however guarantee that no ApplicationException
is ever thrown.
1. With contracts
With code contracts, you may use EnsuresOnThrow
post-conditions:
Contract.EnsuresOnThrow<ApplicationException>( false );
2. Without contracts
Wrap the body of your code in a global try/catch
, and assert False
in the catch block.
In both cases, a static analyzer should understand that the assertion or post-condition can never be true when an exception occurs: thus, the application fullfills its contracts if and only if no exception is ever thrown from your function.