Reputation: 7604
Say you're developing a custom control and there's a key template part that your code requires. If the user of your control overrides the template such that the part no longer exists then what exception should be thrown? Consider:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var grid = GetTemplateChild("MySpecialGridPart") as Grid;
if (grid == null)
throw new WhatExceptionGoesHere();
}
I figured going with XamlParseException was a good choice but that exception has no public ctor. Is there an appropriate exception type for this or should I just throw new Exception()?
Upvotes: 0
Views: 86
Reputation: 70142
Interestingly most framework controls, including those from Silverlight Toolkit do nothing. See the AutoCompleteTextBox for example, where if components of the control are absent, just does nothing!
I don't think the exact exception type really matters, it is unlikely anyone will catch it explicitly. What is more important is that the string message you supply is informative, detailing the name of the template that is missing.
Upvotes: 1