I would like to stop publishing when a certain condition exists in Tridion 2011. In a Razor template I try:
throw new Exception("Exceptional condition!");
But, in Template Builder it says ‘successful’.
Any ideas?
In VBScript templates we would do Err.Raise and it would throw the error back to the Publish Queue.
There’s definitely not any try/catch mechanisms in the base Razor Mediator code, an error in the template should surface (as you see with the common null reference errors you probably run into a lot while razoring it up!). There’s some things you should definitely check:
Is the code path with the exception even being executed? As Bart suggested, you should run it through Template Builder and see if there are any useful logs there. Throw in your own debug statements as well to locate where the code path is going.
Is your Exception in a correctly formatted razor statement?
If its a new CT, does the Page Template’s code allow the rendering of your CT?
I just setup a sample TBB as follows (and added TBB to a Component Template):
Running through Template Builder showed the error in the Output window.
Previewing the page with a component using the CT would fail and show the error.
Publishing the page showed “Failed” as status, with the Processed Items detailing showing the “Exceptional condition!” message.
Hope that helps, if you are still having trouble with it feel free to post your code and I’ll debug it further!