That is not a feature of C#: attributes are not executed as such. There are, however, extension frameworks like PostSharp that would allow this - basically it rewrites the code at the IL level to inject functionality, typically based on attributes. But that requires additional tooling.
In C# "out of the box", your best bet would be:
public int DoSomething() {
CheckValid(); // might throw an exception
return 1;
}