Who needs exceptions

Oleg Broytmann phd at phd.pp.ru
Sat Dec 29 15:46:35 EST 2001


On Sat, Dec 29, 2001 at 04:16:03PM +0000, Gerson Kurz wrote:
> def lower():
>     file = open(...)
>     if file:
>         return file.read()
>     report_error("lower failed()")

   That's wrong solution. Imagine I am writing a library (that includes the
"lower" function). This is  librry, so I cannot define "report_error"
function.
   Later you write few different interfaces to the library - web interface,
text interface (command line), curses, GUI... How can I call different
report_errors()?
   Exception handling solves this easily.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list