The context of a rescued exception

2 views
Skip to first unread message

Matthijs Langenberg

unread,
Sep 26, 2008, 10:00:35 AM9/26/08
to me...@googlegroups.com
Hi all,

When I raise a NotFound exception, and handle that inside my Exception
controller.
I feel like I'm losing the context where the exception got thrown from.
I could raise a NotFound from a Pages controller, but also from a
Users controller,
thought I want to return a message like "page not found" or "user not
found" to the visitor.

I think raising a specific UserNotFound or PageNotFound exception might work,
but I was wondering what you guys are using.

Would it also be possible to get a hold of the original controller?

- Matthijs

Matthijs Langenberg

unread,
Sep 26, 2008, 10:00:39 AM9/26/08
to me...@googlegroups.com

Adam French

unread,
Sep 26, 2008, 1:25:45 PM9/26/08
to me...@googlegroups.com
raise NotFound, "User not found"

Then later in your exception controller

@_message = params[:exception].message

This will toss the exception's message into merb's "message" mechanism
(like Rails flash messages) to provide much more information to the
user about what exactly went wrong. Simply do <%= message %> in view
somewhere and away you go.

Hopefully this helps
===
~ Adam

Yehuda Katz

unread,
Sep 26, 2008, 2:21:58 PM9/26/08
to me...@googlegroups.com
Since a few versions ago, the exception is `request.exceptions', which supports exceptions that raise new exceptions. You usually want request.exceptions.first.

-- Yehuda
--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325

Adam French

unread,
Sep 26, 2008, 2:37:29 PM9/26/08
to me...@googlegroups.com
For a framework which has a contract with it's users over it's public
API staying the same....you sure do change it alot......

===
~ Adam

Michael D. Ivey

unread,
Sep 26, 2008, 2:51:17 PM9/26/08
to me...@googlegroups.com
> For a framework which has a contract with it's users over it's
> public API staying the same....you sure do change it alot......

Exactly.


If the contract says "Once we release Merb 1.0, we're not going to
change the public API for N major releases or M months" then it would
make sense to get it as close to perfect as possible before 1.0 drops.

Yehuda Katz

unread,
Sep 26, 2008, 6:37:42 PM9/26/08
to me...@googlegroups.com
Yep.
Reply all
Reply to author
Forward
0 new messages