Is this a βsituationβ error? If so, just make it throw an exception and don't catch the exception in the override.
If this is not a mistake, then using the return type sounds like a way forward, but it may not be suitable for your context - we really do not know what you are trying to achieve.
Another option is to use a template template:
public abstract class FooBase { public void DoSomething() { DoUnconditionalActions(); if (someCondition) { DoConditionalAction(); } } protected abstract void DoConditionalAction(); }
If you do not want to abstract the base class, you can make it a protected virtual method that does nothing in the base class and is redefined in the derived class where necessary. Please note that DoSomething
is not virtual here.
If none of these options apply, you need to provide us with more specific information about what you are trying to achieve.
source share