Did You Know that You Can Catch and Throw Stuff in Ruby?

While the exception mechanism of raise and rescue is great for abandoning execution when things go wrong, it's sometimes nice to be able to jump out of some deeply nested construct during normal processing. This is where catch and throw come in handy.- Pragmatic Programmers, 2001If like me, you're coming to Ruby from traditional programming languages, the throw and catch methods might surprise you.No, they're not used for throwing and handling errors (although you can use them for that). Instead, they manage the control flow of your Ruby code, by allowing you to terminate execution early and escape deeply nested control flows, without having to use break, return, or raise-rescue.
Did You Know that You Can Catch and Throw Stuff in Ruby? #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/did-you-know-that-you-can-catch-and-throw-stuff-in-ruby

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles