You can generate custom error and warning messages from text templates and display them in the Error List window. You can use this technique to customize the behavior of your text templates for your language users.
To add error or warning messages as text template output
-
In Solution Explorer, right-click the text template file that you want to edit, and then click Open.
The file opens in the editor.
-
Add the following code with the Error and Warning methods to the template:
<#
string name = null;
if(string.IsNullOrEmpty(name))
{
//raise an error, this will appear in the error list
<b>Error</b>("I have no name.");
}
name = "short";
if(name.Length < 6)
{
//raise a warning, this will appear in the error list
<b>Warning</b>("I have a really short name.");
}
#>
<#
Dim name as string = ""
If string.IsNullOrEmpty(name) Then
'raise an error, this will appear in the error list
Me.<b>Error</b>("I have no name.")
End If
name = "short"
If name.Length < 6 Then
'raise a warning, this will appear in the error list
Me.<b>Warning</b>("I have a really short name.")
End If
#>
Note |
|---|
| The Error and Warning methods also have overload methods that take line and column numbers as additional arguments. For more information, see Error and Warning. |
If the template throws any unhandled exceptions, they also appear in the Error List window and stop execution of the template.
For an illustration of using errors and warnings within the context of creating and using a complete text template, see Walkthrough: Creating and Running Text Templates.
Note |
|---|
| To debug text templates, you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates. |
Security
See Also