Why not have just one method instead? E.g. in addition to
EventHandler.Find, add an
EventHandler.MustFind or
MustGet or whatever. Though it might not actually be necessary to put it into the engine itself:
Code: Select all
class EventHandlerHelper
{
static StaticEventHandler MustFind(class<StaticEventHandler> type)
{
let h = StaticEventHandler.Find(type);
if (h == null)
{
ThrowAbortException("Could not find the instance of %s.", type.GetClassName());
}
return h;
}
}
I use similar code in my own mod, it's really nothing more than a safety net for easier debugging. But considering that there is no debugger for ZScript, anything that improves error handling makes it less painful to work with. Suppose I accidentally forgot to register my handler, then I'd receive a meaningful error message instead of a generic "tried to read from address zero" one.