Create a custom macro method.  Your macro method should have all the proper logic and error handling in it.  Then use the global macro in the master template.  I suggest creating a public static method that your macro calls so you can use the static method in your .cs files as well as in your macro.