Re: Proper way to handle errors in a module

2011-05-12 Thread Andrew Berg
On 2011.05.11 01:05 PM, Roy Smith wrote: You want to raise specific errors. Let's say you've got a function like this: def airspeed(swallow): speeds = {european: 42, african, 196} return speeds[swallow] If somebody passes an invalid string, it will raise KeyError as

Re: Proper way to handle errors in a module

2011-05-12 Thread MRAB
On 12/05/2011 20:14, Andrew Berg wrote: On 2011.05.11 01:05 PM, Roy Smith wrote: You want to raise specific errors. Let's say you've got a function like this: def airspeed(swallow): speeds = {european: 42, african, 196} return speeds[swallow] If somebody passes an

Re: Proper way to handle errors in a module

2011-05-12 Thread Andrew Berg
On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like NameError: name 'HelloError' is not defined. I don't know how to define the exception. --

Re: Proper way to handle errors in a module

2011-05-12 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/12/2011 04:12 PM, Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like NameError: name 'HelloError' is not

Re: Proper way to handle errors in a module

2011-05-12 Thread Tycho Andersen
On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like NameError: name 'HelloError' is not defined. I don't know how to

Re: Proper way to handle errors in a module

2011-05-12 Thread MRAB
On 12/05/2011 21:12, Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like NameError: name 'HelloError' is not defined. I don't know how to define the exception.

Re: Proper way to handle errors in a module

2011-05-12 Thread Ethan Furman
Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like NameError: name 'HelloError' is not defined. I don't know how to define the exception. class

Re: Proper way to handle errors in a module

2011-05-12 Thread Andrew Berg
On 2011.05.12 03:20 PM, Corey Richardson wrote: class HelloError(Exception): pass Of course, there are all sorts of other things you could do with your exception. http://docs.python.org/tutorial/errors.html#user-defined-exceptions So that's where that info is. I wasn't looking in the

Re: Proper way to handle errors in a module

2011-05-12 Thread Steven D'Aprano
On Thu, 12 May 2011 15:26:27 -0500, Tycho Andersen wrote: On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like

Re: Proper way to handle errors in a module

2011-05-12 Thread Ben Finney
Andrew Berg bahamutzero8...@gmail.com writes: So that's where that info is. I wasn't looking in the tutorial section. Does this mean you haven't worked through the tutorial? Time to remedy that. -- \ “You are welcome to visit the cemetery where famous Russian and | `\Soviet

Proper way to handle errors in a module

2011-05-11 Thread Andrew Berg
I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't trigger a standard one? Have the function/method

Re: Proper way to handle errors in a module

2011-05-11 Thread Patty
- Original Message - From: Andrew Berg bahamutzero8...@gmail.com To: python-list@python.org Sent: Wednesday, May 11, 2011 10:29 AM Subject: Proper way to handle errors in a module I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering

Re: Proper way to handle errors in a module

2011-05-11 Thread MRAB
On 11/05/2011 18:29, Andrew Berg wrote: I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't

Re: Proper way to handle errors in a module

2011-05-11 Thread Roy Smith
In article mailman.1415.1305134998.9059.python-l...@python.org, Andrew Berg bahamutzero8...@gmail.com wrote: I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just

Re: Proper way to handle errors in a module

2011-05-11 Thread Andrew Berg
On 2011.05.11 12:57 PM, Patty wrote: Hi Andrew - Sometimes you want an exception come up and then use that information to take your program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different

RE: Proper way to handle errors in a module

2011-05-11 Thread Prasad, Ramit
way to handle errors in a module On 2011.05.11 12:57 PM, Patty wrote: Hi Andrew - Sometimes you want an exception come up and then use that information to take your program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want