Since FW/1 is calling your service, FW/1 will catch your error and
invoke the error handling cycle (normally trying to run the main.error
event).
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
There's nothing wrong with a service throwing an exception - if it's
genuinely an exceptional condition and not just an expected "failure"
result. The problem arises if you let FW/1 call services on your
behavior because then you are limiting in how you handle exceptions.
If you explicitly manage and call services yourself - my preference -
then you can wrap calls in try/catch where appropriate. Remember that
exceptions are essentially part of the public API of your service
(because clients need to know about them).
If you explicitly manage and call services yourself - my preference -
then you can wrap calls in try/catch where appropriate.
It depends :)
If the service API includes thrown exceptions to indicate specific
(unexpected) failures then, yes, I'd probably put try/catch in the
controller around the service call. But...
A lot depends on how you want to handle unexpected errors. An
exception is meant to be _exceptional_ by definition. If you make a
service call and it fails (unexpectedly) due to a database problem,
what are you likely to be able to do about it? Again, it depends.
Inserting data and getting a data too big for column error indicates a
failure to properly validate input in your application. You should
probably let the default error handling in FW/1 kick in and open a
ticket in your bug tracking system to add proper field validation.
Calling out to a third party service and getting a connection error...
should probably be encapsulated in your service as an "expected"
failure (and either retried or a known, documented failure result
returned to your controller). But there may be reasonable situations
where your controller calls a service that is known to be able to
throw a given exception and your controller could catch that and do
something other than the default error handling behavior.
In other words, because exceptions should be exceptional and
unexpected, the framework's default error handling is likely to be the
most appropriate solution in most cases. But there could be exceptions
(sic) to that "rule" :)
> Although I've never really seen it discussed, I've always been curious about
> _where_ in their applications people choose to catch an error and deal with
> it.
Error is a fluffy term. Exceptions are one thing. Expected failures
are another. They should be handled differently. You should recover
from a failure (because you expect it) but you probably can't recover
from an exception (because it's unexpected).
HTH
It depends :)
In other words, because exceptions should be exceptional and
unexpected, the framework's default error handling is likely to be the
most appropriate solution in most cases.
Error is a fluffy term. Exceptions are one thing. Expected failures
are another. They should be handled differently. You should recover
from a failure (because you expect it) but you probably can't recover
from an exception (because it's unexpected).
>Since FW/1 is calling your service, FW/1 will catch your error and>invoke the error handling cycle (normally trying to run the main.error
>event).
In 1.x, FW/1 called a service automatically but 2.0 deliberately does
not. That setting lets you have 1.x behavior in 2.0.
Most people outgrow the implicit service calls pretty quickly and it
was causing a lot of confusion, hence the change...
Sean
Cool! With DI/1 it's very easy to manage your model / services and
have FW/1 & DI/1 collaborate to autowire everything.
Now that FW/1 2.0 is gold, my goal is to have DI/1 hit 1.0 fairly
soon. Then I can go back to cfmljure and get that into a more
user-friendly format (not that everyone is going to be interested in
using Clojure with CFML :)
--
FW/1 on RIAForge: http://fw1.riaforge.org/
FW/1 on github: http://github.com/seancorfield/fw1
FW/1 on Google Groups: http://groups.google.com/group/framework-one