Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Why does Ruby identify an exception call as an uninitialized constant?

I am trying to learn (very basic) ruby. The task is to write a couple of exception calls. I was able to write to ZeroDivisionError fine but the FileNotFound is giving me grief. The exception is never thrown because Ruby keeps calling the raising of FNF as an "unintialized constant." I've tried initializing it - not that I knew what I was doing. How can I make this stop so the Exception is raise correctly. The code below is calling the exception where the file exists and then where it doesn't. Thanks.

begin
    File.open("test.txt").each do |line| puts line
 raise FileNotFoundException    
    end
end



begin
    File.open("fauxtest.txt").each do |line| puts line   
raise FileNotFoundException
    end
end

1 Answer

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Discovered by reading around that there is no FNF Exception in Ruby. One must customize it. So, nevermind.