From: Edward Faulkner Date: 2005-10-19T07:16:38+09:00 Subject: Re: Catch/throw vs rescue/raise/retry --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 19, 2005 at 07:07:05AM +0900, Warren Seltzer wrote: > There appear to be 2 separate exception mechanisms in Ruby, catch/throw a= nd > rescue/raise/retry. Is this right? Yes, but they're not used for the same thing. =20 rescue/raise is used to signal error conditions. This is analogous to Exceptions in Java or C++. Throw/catch is used to unwind the stack to a desired point. It's like a labeled break. For example: catch(:done){ loop { do_work if time_to_stop? throw :done } } It's nice because you can break out of arbitrarily nested loops/blocks/etc. regards, Ed --x+6KMIRAuhnl3hBn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDVXO6nhUz11p9MSARAsLzAJwODodjV7xdJofqvlK/RrB7pccXYQCeP4L6 1WBIRDLT5WVBj49i8MFnLUw= =U9vD -----END PGP SIGNATURE----- --x+6KMIRAuhnl3hBn--