ruby-web and trapping errors

Discussion in 'Ruby' started by ivan.pavlov@gmail.com, Jan 17, 2006.

  1. Guest

    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::eek: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...
    , Jan 17, 2006
    #1
    1. Advertising

  2. Guest

    Oops, this was stupid question - I found the answer myself.

    begin
    # code code code
    rescue Exception => detail
    Web::eek:pen do
    puts detail.backtrace.join('<br>')
    puts detail.to_s
    end
    end
    , Jan 17, 2006
    #2
    1. Advertising

  3. Guest

    This is the main reason ruby-web provides a 'web-aware' interpreter.
    There are certain types of errors that Web::eek:pen can't catch,
    especially the dreaded "syntax error".

    If you use the ruby-web interpreter, it will output cgi headers, plus
    the Web::eek: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
    , Jan 21, 2006
    #3
  4. Guest

    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::eek: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.
    , Jan 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlsbA==?=

    Trapping 'compile' errors when aspx page is rendered.

    =?Utf-8?B?QmlsbA==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    505
    =?Utf-8?B?QmlsbA==?=
    Mar 29, 2005
  2. Aaron Fude

    Trapping JNI errors

    Aaron Fude, Jun 1, 2004, in forum: Java
    Replies:
    4
    Views:
    1,486
    Gordon Beaton
    Jun 2, 2004
  3. Avi Kak
    Replies:
    6
    Views:
    309
    Duncan Booth
    Feb 13, 2006
  4. Eitan

    Trapping errors in ASP

    Eitan, Jan 12, 2005, in forum: ASP General
    Replies:
    6
    Views:
    121
    Bob Barrows [MVP]
    Jan 13, 2005
  5. Eitan
    Replies:
    3
    Views:
    126
    Bob Barrows [MVP]
    Jan 12, 2005
Loading...

Share This Page