Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ruby-web and trapping errors

Reply
Thread Tools

ruby-web and trapping errors

 
 
ivan.pavlov@gmail.com
Guest
Posts: n/a
 
      01-17-2006
I am using ruby-web to create a simple web application. Basically I
have some code, I process submitted forms and then I do

Web:pen do
puts html
end

If an error occurs in the code I get : Internal Server Error in the
browser and no information whatsoever about the error.

My question is - can I make the exact error appear in the browser, so I
can fix it easily? I can run my code in console and then I see the
error but if I have user-submitted data before the error occured it
becomes difficult...

 
Reply With Quote
 
 
 
 
ivan.pavlov@gmail.com
Guest
Posts: n/a
 
      01-17-2006
Oops, this was stupid question - I found the answer myself.

begin
# code code code
rescue Exception => detail
Web:pen do
puts detail.backtrace.join('<br>')
puts detail.to_s
end
end

 
Reply With Quote
 
 
 
 
patsplat@gmail.com
Guest
Posts: n/a
 
      01-21-2006
This is the main reason ruby-web provides a 'web-aware' interpreter.
There are certain types of errors that Web:pen can't catch,
especially the dreaded "syntax error".

If you use the ruby-web interpreter, it will output cgi headers, plus
the Web:pen block is not needed:

#!/usr/bin/ruby-web

....
puts html

This will catch the error and display to the browser. The cgi
interpreter works on Windows and Unix platforms, with fastcgi support
in linux if you installed the fcgi libraries. There are also ruby-web
handers for ModRuby which provide the same support. All the gory
details are at:

http://ruby-web.org/manual/install.html

Thanks for trying it out!

Cheers,

Patrick

 
Reply With Quote
 
ivan.pavlov@gmail.com
Guest
Posts: n/a
 
      01-21-2006
Patrick, thanks for the pointer to #!/usr/bin/ruby-web , I missed this
during the installation. Well, I guess I missed all the install
instructions.

I am very new to Ruby and am just exploring different things. Rails is
far too much for my needs and I found ruby-web does exactly what I
want. I probably use like 1% of its capabilities, because all I really
need are the data submitted by the user, once I have them, all the
program flow goes through various classes which in the end return a
string cotaining the whole HTML of the page. All the logic is in the
classes and I do not need to output anything piece by piece. So, in the
end I have a string which I pass to a single Web:pen block and I'm
done.

I am using templates of course; having programmed in PHP for several
years I hate plain HTML in my code, so I took probably the worse
approach - wrote a small template engine myself, for reasons described
below.

In the end, I have to say I'm beginning to like Ruby. Code is shorter
than PHP and more elegant, which does not necessarily mean it takes
less time to write but sometimes it does. My only frustration is the
lack of good documentation for the external libraries I download from
rubyforge. Most people seem to think that a hastily prepared rdoc is
enough, and that examples are not really necessary because the user has
like 5 years of Ruby experience and understatnds everything just by
looking at a method name. I am not speaking here about the core classes
and methods which are indeed very well-documented.

I know that writing documentation is a pain. But this can really speed
up adoption of the language. Good, working examlpes of something
meaningful are the best documentation.


p.s. Patrick, this entry is in no way connected to ruby-web, I got
frustrated over some other libraries, like rexml.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trapping errors in function call syntax Avi Kak Python 6 02-13-2006 09:25 PM
Trapping 'compile' errors when aspx page is rendered. =?Utf-8?B?QmlsbA==?= ASP .Net 4 03-29-2005 04:05 AM
Trapping errors in ASP Eitan ASP General 6 01-13-2005 12:59 PM
Trapping an errors to a fixed page (ASP) Eitan ASP General 3 01-12-2005 01:48 PM
Trapping JNI errors Aaron Fude Java 4 06-02-2004 08:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57