[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exception handling
I disagree with the analysis that having custom exceptions
which do nothing more than extend the standard exception
is not smart. What happens when you have a certain
specific situation to you application and you need to
throw an exception, but do not need the exception to
provide any more functionality than the base class? Are
you just going to throw Exception? Than somewhere you
would have to have a catch(Exception e) or catch(Throwable
t) block and at that point you have no way of knowing what
the exception is without further examination. At the very
least, extending a base Exception can identify a specific
situation without ever having to examine the object. Also
the catch blocks can be setup to catch specific exceptions
that the code may care about and one catch block for a
more general exception to catch the exceptions that it
will handle the same way.
This is a great use of inheritence because you have
written an entire class specific to your situation without
having to write more than a simple class definition and
some constructors. Whether or not you would make this
class a RuntimeException is a different discussion.
On Tue, 25 Nov 2003 08:00:16 -0800 (PST)
Poorav Chaudhari <pooravc@yahoo.com> wrote:
>Hi Rajan,
>
>Thanks for your response. I would just like to point out
>that I do not have any
>EJBs, anyhow I can use a similar approach with my Data
>access objects. can you
>be a little more specific as to what you mean by
>application exceptions. I was
>reading a write up which talked about when to throw
>checked exceptions and when
>to throw unchecked exceptions. The article also pointed
>out that throwing
>custom exceptions that did nothing more than just extend
>the standard
>Exception, was not a very smart implementation. any
>thoughts on that?
>
>Thanks.
>Poorav
>--- Rajan Gupta <rajangupta@rocketmail.com> wrote:
>> One possibility is
>> Services from the EJB tier raise application exceptions,
>>which are
>> caught by service delegates or Action classes depending
>>upon your
>> abstraction on the client tier. Each application
>>exception caught in
>> the Action class is translated to a key in application
>>resources, the
>> error is stored using saveErrors() & then finally
>>displayed in the JSP
>> page using the <html:errors/> tag.
>>
>>
>> --- Poorav Chaudhari <pooravc@yahoo.com> wrote:
>> > Hello,
>> >
>> > I am developing a struts based application. Mostly
>>everything is
>> > running
>> > smoothly. But I am having difficulty coming up with an
>>effective
>> > structure for
>> > exception handling. How should the exceptions be
>>handled at the data
>> > access
>> > layer, and how should they be handled at the business
>>layer (i don't
>> > have any
>> > ejbs). I have read a few articles on the web regarding
>>this, all they
>> > have done
>> > is gotten me a little more confused! I would really
>>like to see how
>> > some of you
>> > have handled this. suggestions, tips, examples are
>>all very welcome,
>> >
>> > waiting in anticipation.
>> >
>> > =====
>> > - Poorav
>> >
>> > __________________________________
>> > Do you Yahoo!?
>> > Protect your identity with Yahoo! Mail AddressGuard
>> > http://antispam.yahoo.com/whatsnewfree
>> >
>>
>>
>> __________________________________
>> Do you Yahoo!?
>> Free Pop-Up Blocker - Get it now
>> http://companion.yahoo.com/
>
>
>__________________________________
>Do you Yahoo!?
>Free Pop-Up Blocker - Get it now
>http://companion.yahoo.com/
>