[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

in-eval exception

Jacek

1/27/2005 11:30:00 AM

Hi
I use evals very often in our system. I start to think about little, on page
tracker so I decided to use PrettyException. I overloaded my class
(MException < PrettyException) to add a ability to read evals, and then
the problem came: The only way I can acces code I use with eval is to
create global variable with value of the code and then put this variable
into the code itself (well better look )

########################################################
$str="
begin
raise
rescue => e
puts MException.new($str,e).print_exception()
end
"

eval $str
#########################################################

Inside Exception I need this code to parse it on the page.
Is ther another better way to access eval param (my code)
from inside MException considering that MException is called
inside eval ?
Sorry for my lang. , Jacek Balcerski
1 Answer

Robert Klemme

1/27/2005 12:27:00 PM

0


"Jacek" <balcer@future-net.pl> schrieb im Newsbeitrag
news:ctajdt$346$1@portraits.wsisiz.edu.pl...
> Hi
> I use evals very often in our system. I start to think about little, on
page
> tracker so I decided to use PrettyException. I overloaded my class
> (MException < PrettyException) to add a ability to read evals, and then
> the problem came: The only way I can acces code I use with eval is to
> create global variable with value of the code and then put this variable
> into the code itself (well better look )
>
> ########################################################
> $str="
> begin
> raise
> rescue => e
> puts MException.new($str,e).print_exception()
> end
> "
>
> eval $str
> #########################################################
>
> Inside Exception I need this code to parse it on the page.
> Is ther another better way to access eval param (my code)
> from inside MException considering that MException is called
> inside eval ?
> Sorry for my lang. , Jacek Balcerski

Simply catch the exception outside the eval:

def foo(code)
begin
eval code
rescue Exception => e
puts MException.new(code,e).print_exception()
end
end

Does that help?

Kind regards

robert