ruby - Why is a syntactic error in a subfile designed to be rescued by `require`? -
as asked liron in this question, syntax error in require
-d subfile rescued method require
, raised error of require
. why designed this? benefit of attributing error require
, not syntax error in subfile read? understanding feature introduced when gem system became standard part of ruby. related that.
the relevant portion of stack trace in question:
/home/***/.rvm/.../rubygems/core_ext/kernel_require.rb:45:in `require': .../food_finder/lib/restaurant.rb:84: syntax error, unexpected end-of-input, expecting keyword_end (syntaxerror)**
it does error is.
the syntax error wrapped in error require
because that's error raised: file being processed require
method. if there's error in required file, it's wrapped error handling in require
.
it's rescued require
(and potentially re-raised) original require
method can tried under variety of circumstances relating not finding file , gem failures.
are suggesting require
, method, somehow special-cased error handling operates in different way? , roi of doing worth it?
the "benefit" not subverting how ruby works remains uniform. see little roi in doing when error explicitly stated. of confusion may come not grokking require
method–but is, , such, follows same rules rest of language.
Comments
Post a Comment