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 no throw?

    perhaps there throw before, , programmer forgot delete catch when throw deleted, or doesn't know how use catch.

    but more in case failed ask "why catch block executed if there no throw?" answer question catch block executed point throw raised. if throw not raised, catch block executed.

  • is there 1 liner syntax?

    yes. don't omit parentheses.

    catch(:something){print true} 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -