• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exception handling

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i have following code



why is CDCRuntimeExceptionHandler not able to catch ArithmeticException and display you are here
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because ArithmeticException is not a subclass of CDCRuntimeExceptionHandler
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

CDCRuntimeExceptionHandler not able to catch ArithmeticException



Cous...

Class B extens A {}
Class C extans A {}

Can you use..
B=C
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the CDCRuntimeExceptionHandler is super class of ArithmeticException and if i am not wrong the super class can catch sub-class exception.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by N Chaurasia:
But the CDCRuntimeExceptionHandler is super class of ArithmeticException and if i am not wrong the super class can catch sub-class exception.



How is CDCRuntimeExceptionHandler a superclass of ArithmeticException?
[ June 19, 2006: Message edited by: Keith Lynn ]
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pinkal,
i cannot say B=C, but i can say : CDCRuntimeExceptionHandler = ArithmeticException and CDCRuntimeExceptionHandler = RuntimeException since in both cases the CDCRuntimeExceptionHandler is super class.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
keith when i say CDCRuntimeExceptionHandler is super class of ArithmeticException , i mean that CDCRuntimeExceptionHandler is extending RuntimeException and RuntimeException is allowed to catch ArithmeticException

 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But that doesn't make CDCRuntimeExceptionHandler a superclass of ArithmeticException.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes true, but CDCRuntimeExceptionHandler is extending RuntimeException and then CDCRuntimeExceptionHandler should inherit the feature of RuntimeException and hence be allowed to catch the ArithmeticException....i agree that CDCRuntimeExceptionHandler is not super class of ArithmeticException
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it doesn't inherit that property.

CDCRuntimeExceptionHandler is a subclass of RuntimeException.

But it doesn't have any relation to ArithmeticException.

You'll need to make the parameter in the catch block ArithmeticException or one of its superclasses.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You'll need to make the parameter in the catch block ArithmeticException or one of its superclasses



RuntimeException is super class of ArithmeticException
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But CDCRuntimeExceptionHandler isn't.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i think i got your point.....but in that case, if i am writing my custom exception handler for my application, then how will i catch all the exception and handle them...

lets consider the original code is posted.. if there is some run time exception occuring that what can i do to handle that exception.




if i do something like this, is it fine
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my basic purpose of throwing is CDCRuntimeExceptionHandler is that i have defined error file corresponding to CDCRuntimeExceptionHandler in my web.xml so that when ever my application throws error i can handle it declaratively using web.xml

 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you can. But it may not do what you want.

If you make the net too wide, then it will catch all exceptions.

You might want to rethink how you're handling exceptions.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i agree, but if i define custom exception than i face the problem...can u suggest me some way to work with custom exceptions...so that i can log error message specific to my application
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're going to open the net wide, then you could use the instanceof operator or getClass() to determine the type of exception.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok if i do not want to open the net wide, what is other way i can use to achieve custom exception handling...
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have several catch blocks.
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chaurasia,


i can say : CDCRuntimeExceptionHandler = ArithmeticException and CDCRuntimeExceptionHandler = RuntimeException since in both cases the CDCRuntimeExceptionHandler is super class.



CDCRuntimeExceptionHandler = ArithmeticException // Not Alloved Pls Check
CDCRuntimeExceptionHandler = RuntimeException // This is valid
CDCRuntimeExceptionHandler is super class // I thing this is not currect

RuntimeException is super calss of both the Exception CDCRuntimeExceptionHandler and ArithmeticException

So if we catch the RuntimeException both will catch in runtime excpetion.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx Pinkal,
i have found out where i was going wrong...have you worked on custom exception handling.....handling different kinds of exception in your application, catching them and logging them, by defining custom exception handler
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx Pinkal,
i have found out where i was going wrong...have you worked on custom exception handling.....handling different kinds of exception in your application, catching them and logging them, by defining custom exception handler...can you give me some suggestion about it
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure,

But it will depande on the your requerment and application architechture.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I would suggest the following:



By creating and throwing your custom exception in an method you can then catch the custom exception when you call the method.

Not sure if this helps.

Finner
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I told,

It is totaly depand on the Application requrment.

This is perfecly Legal for this program but not help full in real application.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic