Syntax

Ruby Begin / Rescue Syntax

In Ruby, begin / rescue: handles exceptions — begin ... rescue StandardError => e puts e.message end

Quick Answer

Syntax
begin ... rescue StandardError => e puts e.message end
RubySyntax

Begin / Rescue

Code example
begin ... rescue StandardError => e puts e.message end

Handles exceptions.

Learn More

How to begin / rescue in Ruby

  1. Open your Ruby file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Ruby Begin / Rescue Syntax

Use begin ... rescue StandardError => e puts e.message end.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for begin / rescue?

Use this pattern: begin ... rescue StandardError => e puts e.message end

Can I copy this Ruby code example?

Yes. Use Copy code and adapt the example to your program.

Is this Ruby syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify