Thanks, Daniel, you've answered my question and provided great rationale. Cheers. Steve
On Apr 29, 7:36 pm, Richtermeister <[email protected]> wrote: > Hey Steve, > > as a general rule, any exception (even a normal php exception) that > you throw from within your code will ultimately be caught by symfony > and displays either an error 500 or a stacktrace (in dev mode), UNLESS > you catch the exception within your own code first. > > Creating your own exception classes is a good idea, because it enables > you to throw and catch exceptions without interfering with the > exceptions that symfony throws for itself. > > For example, if you wrap a call to one of your own classes into a try/ > catch block, and your catch statement is looking for an sfException, > you could intercept all sorts of symfony exceptions (database, > configuration, etc) without really being in the right place to handle > those, since they're supposed to be handled on a higher level (logged, > displayed, forwarded to 500, etc). > So, you don't want to deal with those exeptions, and therefore you > create your own (doesn't matter if based on sfException, although it > saves the framework the extra step of converting your exception to a > symfony exception). > > I usually have at least one exception for each functional area of my > application. Say you have a "package" of classes that manage an > external email list via service, that package for me would contain an > "EmailApiException".. > > For apps with an ecommerce store I also include a more powerful > "StoreException" which takes down the store and displays a nice > "Sorry, come back later" message.. If, say, my shipping integration > code throws a ShippingApiException, the controller code can then > decide if it wants to throw the StoreException.. so, having some > granularity there is important to delegate the decision-making from > specific areas to more general areas of code. > > Hope that all made sense, > Daniel > > On Apr 29, 6:39 am, Steve the Canuck <[email protected]> wrote: > > > I haven't been able to find out much from the documentation regarding > > how to throw exceptions in my code and how Symfony will deal with > > them. I'm not talking about 404 errors and stuff, I know how to > > handle those. But I have some cases where I encounter exception > > conditions in my business logic (within the OM) and I need to throw an > > exception. > > > My questions are: > > > - should I create my own exception classes for my application, and > > should they be extending sfException? > > - how will symfony handle application exceptions? > > > Thanks, > > Steve --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
