Just a simple gripe, nothing much.
Why didn't Microsoft put a params based constructor on Exception?
I am not a lazy coder, but I cannot count the number of hours I've wasted dealing with compiler errors because I have done something like
throw new InvalidOperationException
("Cannot load invalid {0}", typeof(TAdapter));
instead of
throw new InvalidOperationException
(string.Format("Cannot load invalid {0}", typeof(TAdapter)));
I have written my own class (for my own work), but I have yet to implement it at work, and I still keep forgetting (or remembering and cursing) that damnable string.Format
namespace ObviousCode.Common.Utils.Library.Exceptions
{
[DebuggerStepThrough()]
public class ExceptionBuilder
{
//For use when the compiler does not need to be aware that the code
//has halted -
//ExceptionBuilder.Format(...)
public static void Format(string message, params object[] args)
{
throw Get(message, args);
}
//For use when the compiler needs to be aware that the code has halted -
//throw ExceptionBuilder.Get(...)
public static InvalidOperationException Get
(string message, params object[] args)
{
return new InvalidOperationException(
string.Format(message, args));
}
}
}
