- .NET library has documentation comments, with <exception> tags
- It could look at my code and see what exceptions get thrown.
- It could be clever enough to know that new might throw OutOfMemoryException
- Clever enough to know checked arithmetic might throw OverflowException
- Might understand where/what exceptions get caught and do not bubble up.
- Smart enough to understand if value can possibly be null and properties are accessed, thus may result in ArgumentNullException.
- As for 3rd party code, I don't know if .pdb provide enough info to know whether particular function call may throw particular exception? But it's all IL, so that should be enough to infer from 3rd party code what kind of exceptions I might encounter:
// throw new ArgumentNullException("serviceProvider");
IL_0013: ldstr "serviceProvider"
IL_0018: newobj instance void [mscorlib]System.ArgumentNullException::.ctor(string)
IL_001d: throw
Eh, what a dream.