Writing better exception Strikes Back!
Hmmm, as pinpointed by my good friend Claudio Figueiredo, the compiler isn't very thrilled with my last syntax:
1: public string MyCode(){ 2: try{ 3: return "some value";
4: }
5: catch(System.Exception ex){ 6: Throw
7: .WithMessage("something") 8: .WithInnerException(ex)
9: .Exception<InvalidOperationException>();
10: }
11: }
You actually get a compiler error saying you need to return something, or something like that. That's because there's no way of telling dumb ol' compiler that the Throw.Exception<ExceptionType> method is actually a replacement for throw.
Ok, after I got over being angry at the compiler, I decided on having a different syntax (not as neat as the first one, but accomplishes the same):
1: throw NewException.WithMessage("Something happened") 2: .Because("Why did this happen") 3: .WithWorkaround("What can I do about it") 4: .Of<InvalidOperationException>();
Hope it helps!
#142