Compile to throw Doesn't Not Compile
Let's say you have a method
public void Foo()
{
SomeMethodThatDoesntExist();
}
Right Now this will not produce a dll, as it won't compile. Which will causes lot's of false positives and prevents me from testing other pieces of code until I fix that method.
I would like to suggest it DOES compile, but instead compiles to a method that throws a DOES NOT COMPILE exception.
Effectively:
public void Foo()
{
throw new DoesNotCompileException("[Insert Actually compilation message here"]);
}
This would allow me more freedom to work and test things as I go, plus would prevent a false run against an out of date dll.
2 comments
-
Philippe
commented
The IDE already write thrown new NotImplementedException() in most method it generate when generating stub. Just do the same. And you can always add a code snippet like tni that would write the above code with 4 keystrokes...
-
Qwertie
commented
I have had the same idea myself. IMO the compiler should have a mode where it replaces errors (whenever possible) with exceptions, and deals with errors outside function bodies in whatever way is most appropriate. e.g. syntax error in a class? Just ignore the error. A class contains a member with an unrecognized data type? Just omit that member from the emitted assembly, and throw an exception from any code that tries to access it.