Catch throw?

Hello,

I just started using catch and throw. Therefore this question might be an
easy one.

I have multiple ruby files. In one of the files I like to throw and then in
the main function in a different file I like to catch the throw. Is this
possible or do throw/catch need to be in the same file?

Example:
fileOne.rb

def somefunct
....
throw :quit_script
....
end

fileTwo.rb
catch :quit_script
...
end

Thx,
Bernd

They have to be in the same call chain.

so if fileTwo require's fileOne.rb and fileTwo's code looks like
catch :quit_script do
    ...
    somefunct()
   ...
end

it will work

···

On Mar 8, 2006, at 8:35 PM, Paatsch, Bernd wrote:

Hello,

I just started using catch and throw. Therefore this question might be an
easy one.

I have multiple ruby files. In one of the files I like to throw and then in
the main function in a different file I like to catch the throw. Is this
possible or do throw/catch need to be in the same file?

Example:
fileOne.rb

def somefunct
....
throw :quit_script
....
end

fileTwo.rb
catch :quit_script
...
end

Thx,
Bernd

harp:~ > cat a.rb
     p catch('answer'){ load 'b.rb' }

     harp:~ > cat b.rb
     throw 'answer', 42

     harp:~ > ruby a.rb
     42

hth.

-a

···

On Thu, 9 Mar 2006, Paatsch, Bernd wrote:

Hello,

I just started using catch and throw. Therefore this question might be an
easy one.

I have multiple ruby files. In one of the files I like to throw and then in
the main function in a different file I like to catch the throw. Is this
possible or do throw/catch need to be in the same file?

Example:
fileOne.rb

def somefunct
....
throw :quit_script
....
end

fileTwo.rb
catch :quit_script
...
end

Thx,
Bernd

--
knowledge is important, but the much more important is the use toward which it
is put. this depends on the heart and mine the one who uses it.
- h.h. the 14th dali lama