c# - Is it good practice to throw exceptions in virtual functions? -
Even though the solution is so obvious, I should never have posted it, I leave it as one I am a useful point of reference to reminders and others.
I've got the following base classes:
using the system; Nameshot Library WFF {Public Class Library} /// & lt; Summary & gt; /// Item removed when the content has been added to libary /// & lt; / Summary & gt; Public event event handler & lt; ObjectInfoEventArgs & gt; Library_ObjectAdded; /// & lt; Summary & gt; The event has been removed when the scan of the /// library is finished /// & lt; / Summary & gt; Public Events EventHandler Library_Finished; // Properties /// & lt; Summary & gt; / / Whether to stop checking the library or not /// & lt; / Summary & gt; Public stops {get; Set; } /// & lt; Summary & gt; /// Where to view content, /// & lt; / Summary & gt; Public string root {get; Set; } /// & lt; Summary & gt; Exclamation of Library Objects for /// Reflection /// & lt; / Summary & gt; Public Virtual Object ObjectInfo {get {// should take it as an exception to show if it is not overridden? Return tap; }} /// & lt; Summary & gt; The /// subclass overrides this method to call the actual search code /// & lt; / Summary & gt; Find public virtual zeros () {// Should it be taken as an exception to show whether it has not been overridden? } /// & lt; Summary & gt; Create a /// Library /// & lt; / Summary & gt; Public Zero Build () (if (root! = Null & root; gt;); {stop = false; search ();} // Last update if (Library_Finished! = Null) {Library_Finished (This, empty );}} /// & lt; Summary & gt; /// All Class calls this method for the object adware event / fire; & lt; / summary & gt; /// & lt; param name = "ObjectInfo" & gt; Object added to the library & lt; / param & gt; protected zero OnObjectAdded (object objectInfo) {if (Library_ObjectAdded! = Null) {Library_ObjectAdded (this, new ObjectInfoEventArgs (objectInfo))}} }} Override subclasses To return an event type of object used by ObjectInfo reflection, they also override find to do actual searches.
So - my question is:
Or i ObjectInfo look to sub-class can not be applied properly, I get run-time error? Or ObjectInfo back null ?
If you want a method to be implemented by derived classes, why not use it instead of virtual Do not make it? It will force the derived class to implement the member. If they do not want to do this or can not return anything, then they can choose to empty themselves.
Comments
Post a Comment