Trial and error method in mathematics and other theoretical sciences means some different technique as compared to experimental sciences. In mathematics, sometimes one indeed can use a software program to use this method, say to approximate some experimental curve with an analytical function within certain error limits through an optimization process. Alternatively certain theoretical problems can be studied without computer simulations, but just analyzing various situations by using say a simultaneous way of thinking, and using trial and error method in analyzing different logical chains.
In experimental sciences, trial and error method can be efficient, when an 'error' means an opportunity to exclude a certain experimental option from farther considerations, or a possibility in using it as an encouraging hint as to how to modify the next trial. The efficiency of this method would depend on how good is the experimenter's strategy in reducing the number of trials to a possible minimum, or to reduce the time for the project, or to reduce the money spent to get an acceptable result.