ruby - Why is a `catch` block called if there is no `throw`? -
the following:
catch :something print true end
will print true
console. thought point of catch
was called corresponding throw
.
less importantly, there 1 liner syntax? surprised catch :something { print true }
raises syntaxerror
.
why
catch
block called if there nothrow
?perhaps there
throw
before, , programmer forgot deletecatch
whenthrow
deleted, or doesn't know how usecatch
.but more in case failed ask "why catch block executed if there no
throw
?" answer questioncatch
block executed pointthrow
raised. ifthrow
not raised,catch
block executed.is there 1 liner syntax?
yes. don't omit parentheses.
catch(:something){print true}
Comments
Post a Comment