Is there a way to decorate a method that will do some logging, then throw an exception unconditionally, as such?
I have code like this:
void foo(out int x)
{
if( condition() ) { x = bar(); return; }
// notice that x is not yet set here, but compiler doesn't complain
throw new Exception( "missed something." );
}
If I try writing it like this I get a problem:
void foo(out int x)
{
if( condition() ) { x = bar(); return; }
// compiler complains about x not being set yet
MyMethodThatAlwaysThrowsAnException( "missed something." );
}
Any suggestions? Thanks.