On Thu, 07 Apr 2005 15:40:24 -0400, Steve Holden <[EMAIL PROTECTED]> wrote:

>Leo Breebaart wrote:
>> I've recently become rather fond of using Exceptions in Python to
>> signal special conditions that aren't errors, but which I feel
>> are better communicated up the call stack via the exception
>> mechanism than via e.g. return values.
>> 
>Absolutely.
>
>> For instance, I'm thinking of methods such as:
>> 
>> 
>>     def run(self):
>>     """ Feed the input file to the simulator. """
>> 
>>         for linenr, line in enumerate(self.infile):
>>             try:
>>                 current_values = self.parse_line(linenr, line)
>> ==>         except CommentLineException:
>>                 continue
>>             results = self.do_one_simulation_step(current_values)
>>             self.process_simulation_results(results)
>> 
>> 
>> which I use in order to discard comments from a file I'm parsing
>> line-by-line.

It also possible for exception arguments to deliver a result, rather
than indicate something rejected. E.g., you can terminate a recursive
search via an exception. If no exception occurs, you have gone through
the entire search space and not met the solution criterion.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to