saurzcode
saurzcode

Reputation: 837

Handling Exception thrown from Custom View Resolver

I have a custom view resolver(s) and an exception resolver. When an exception is throw from the controller code, the exception resolver is called and the exception is mapped onto the view with error message.

However, when I throw an exception from one of the view resolvers, it propagates up to the application server, and is not resolved with registered exception resolver.

I suppose this happens because exception resolver is 'below' view resolvers, since the views returned by it must be resolved... and so exceptions from view resolvers are thrown outside.. but still I do not know how to deal with that situation in a well-designed way.

Please suggest.

Upvotes: 2

Views: 1073

Answers (1)

skaffman
skaffman

Reputation: 403611

Typically, when an exception resolver handles an exception thrown from a controller, it returns a view name so that the error page can be rendered.

So if a view resolver were to throw an exception, what could you meaningfully do with it? The error eventually has to be rendered in some way, but who's going to resolve that view, if not the view resolver itself?

To answer your question, I'm not aware of any mechanism to catch exceptions thrown by view resolvers, other than the standard servlet container mechanism. If you have error conditions within your view resolver, I suggest you either (a) fix them (if they're bugs), or (b) catch those exceptions within the view resolver, and render a different view displaying the error.

Upvotes: 1

Related Questions