• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Exceptions Doubt  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ThrowDemo
{
static void throwOne()
{
System.out.println("Inside throwone");
throw new ArithmeticException();
}

public static void main(String[] args)
{
throwOne();
}
}


Why does this compile fine?

1)Don't we have to handle or declare exceptions which are thrown by methods
using the 'throw' clause??

2) Is there an exhaustive list of an exception hierarchy that we need to memorize for the exam?

Thanks a lot!
 
Ranch Hand
Posts: 811
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArithmeticException is uncheked exception so no need to declare or handle it
if it is other than unchecked exception then it must be declare or handle by method

unchecked exceptions are Error and RuntimeException but error should not be handled because program may not recover from ocuured error

checked exceptions are other than Unchecked Exception

If I am wrong then notify me for that

Regards
Ninad

[ June 22, 2008: Message edited by: Ninad Kulkarni ]
[ June 22, 2008: Message edited by: Ninad Kulkarni ]
 
dedcat achi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

You are correct.
However, how do you explain this:

When the IllegalClassFormatException is typed using the throw keyword, then an error message of cannot find symbol is displayed along with its location.

But when the IlegalAccessException is used, I get the error message saying that it should be declared or thrown which should've been the case for above as well.


Now, both are checked exceptions, then why the difference in the error message?
 
Ninad Kulkarni
Ranch Hand
Posts: 811
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both are checked exception and I got compiler error for both type of exceptions to declare it or handle

Regards
Ninad
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!