I'd like to have a function take a statement as a parameter, either as a string or as some other type that I'm not aware of, and return true if the execution of that statement throws an exception, and false otherwise.
This may rely on some sort of "string" execution, which I have no idea how to do in C#.
It would be better to use a unit test framework, such as NUnit, or Visual Studio Team Test:
To say that a method should throw an exception you add the
ExpectedException
attribute, for example:If you don't add this attribute and the method throws then the test automatically fails.
For completeness I'll also answer the question you asked: you can't execute a string but you can pass an Action as a parameter.
You can use it like this, for example: