From: Jim Weirich Date: 2006-01-20T04:36:45+09:00 Subject: Re: rdoc, api + exceptions jon baer wrote: > Normally when developing an API you can express what exceptions may > occur when invoking a particular method ... > > public foobar() throws BadFooBarException > > In Ruby, it would seem to me that nearly ~everything~ can throw at > least one exception (or at least cause NameError), so Im wondering at > least how you would document that your method should be placed in a > begin/rescue/end block from a custom exception. I follow a simple rule when dealing with exceptions and it works equally well in Java or Ruby. Every method has a purpose. If a method is unable to achieve its purpose, then it must fail (and indicate failure via an exception). So when do you wrap a method in a begin/rescue clause? When the failure of a called method should not cause the failure of the calling method. Rescue the failure, attempt to fix it and continue. When you think of the problem in terms of success/failure, then the type of failure is usually not important. This means you don't (usually) have to worry about exactly which type of exception is being thrown and making sure you capture each and every possible exception type (which creates quite fragile programs IMHO). -- -- Jim Weirich -- Posted via http://www.ruby-forum.com/.