SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Errorhandling

  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Errorhandling

    How do you handle errors ocurring throughout your application?
    I have this example, say a user is trying to view a product that does not exist: The user makes a query to view a product with id = 1 and there is no product in the database with that id. A ActiveRecord::RecordNotFound exception is thrown.

    Now what do i do?

    Should i have a specific controller which i pass all errors to be taken care of. Or should i handle the error in the current controller and action?

    Then it comes to my mind that this is one type of problem which maybe should be handled one way. On the other side, user input in forms that are not valid is one type of error and maybe should be handled in another way?

    I just want some thoughts about this, and how you design your app.

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you use dynamic finders they dont error when nothing is found with your query. Kiek this:

    Say your model is User and you want to find by the id in the params:

    @user = User.find_by_id(params[:id])

    That will work without throwing an error if your find returnjs nil.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •