• 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

Need I?remember all this things?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is from Dan Chisholm's Mock Exam
----------------------------------------
1. class A {
2. void m1() {throw new ClassNotFoundException();}
3. void m2() {throw new ArithmeticException();}
4. void m3() {throw new ClassCastException();}
5. void m4() {throw new IllegalArgumentException();}
6. void m5() {throw new CloneNotSupportedException();}
7. void m6() {throw new NoSuchFieldException();}
8. }
What is the result of attempting to compile the program?
a.
Compiler error at line 2.
b.
Compiler error at line 3.
c.
Compiler error at line 4.
d.
Compiler error at line 5.
e.
Compiler error at line 6.
f.
Compiler error at line 7.
g.
None of the Above
---------------------------------------------
I just wondered if I take the scjp,should I remember all the subclasses of RumTimeException And Exception??I think it's really a hard work.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The purpose of this question is to distinguish which are check exceptions and which are run time exceptions. I think it's unnecessary to remember all of them except some very common appearing ones.
 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I think the point is how to distinguish which are check exceptions and which are run time exceptions only depends on the class name whithout memorized to many things??
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun,
The purpose of the question is to verify that a person is able to distinguish between those exceptions that must be declared in the throws clause of a method and those that do not. In other words, which exceptions are subclasses of RuntimeException? A good way to recognize the subclasses of RuntimeException is by understanding that a RuntimeException represents errors that are generally a result of some sort of programming error. For example, if you have an array with only five elements then you will get an ArrayIndexOutOfBoundsException if you try to access the sixth element. If you try to divide by zero, then you will get an ArithmeticException. If you try to invoke a method using a null reference, then you will get a NullPointerException.
In contrast to RuntimeException, many other exceptions are not a result of a coding error. For example, a ClassNotFoundException could be a result of a deployment error. An OutOfMemoryError may be a result of hardware limitations.
Imagine how complex your code would be if you had to check for an ArrayIndexOutOfBoundsException each time you access a member of an array. Image how complex your could would be if every division operation had to be placed inside a try/catch block so that you can always catch the ArithmeticException that is thrown as a result of an attempt to divide by zero. The RuntimeException class was created to avoid unnecessarily complex code. If you understand the purpose of the class, then recognizing the subclasses becomes easier.
Having said the above, it would be interesting to hear what others have to say about exception classes and the level of memorization necessary for the exam.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The SCJP 1.2 objectives are a little vague about exception handling.


- Write code that makes proper use of exceptions and exception handling clauses (try, catch, finally) and declares methods and overriding methods that throw exceptions.


They have gone a little more in depth in the 1.4 version of the exam:


- Write code that makes proper use of exceptions and exception handling clauses (try, catch, finally) and declares methods and overriding methods that throw exceptions.
- Recognize the effect of an exception arising at a specified point in a code fragment. Note: The exception may be a runtime exception, a checked exception, or an error (the code may include try, catch, or finally clauses in any legitimate combination).


Personally, I would say that any respectable Java programmer (informal requirement for the exam ) should be able to recognize the most common checked and unchecked exceptions and how to handle them.
[ August 11, 2002: Message edited by: Valentin Crettaz ]
 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot to Dan.It help me a lot to memerize this.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Re: memorization - let's start a new topic!
-Barry
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Crettaz:
Personally, I would say that any respectable Java programmer (informal requirement for the exam ) should be able to recognize the most common checked and unchecked exceptions and how to handle them.
[ August 11, 2002: Message edited by: Valentin Crettaz ]


I agree completely!!!
- Manish
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what is the correct answer to this question?
Thanks
Barkat
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll repeat the question here before giving you the answer.

All six methods throw an exception but none of the methods declare the exception in the throws clause. The methods that throw exceptions that are a direct subclass of the Exception super class and are not a subclass of RuntimeException will generate a compiler error. The methods that throw exceptions that are a subclass of RuntimeException will not generate a compiler error.
Method m2 throws an ArithmeticException. That's an exception that is thrown as a result of an attempt to divide by zero. Ask yourself if you must always enclose in a try/catch block any expression that envolves division.
Method m3 throws a ClassCastException. Ask yourself if you must always enclose a cast expression in a try/catch block.
Method m4 throws an IllegalArgumentException. That's an exception that is thrown anytime you attempt to pass the wrong type as a method parameter. Ask yourself if you must enclose all method calls in a try/catch block so that you can catch an IllegalArgumentException.
Methods m2, m3, and m4 do not generate compiler errors, but the other method declarations do.
 
reply
    Bookmark Topic Watch Topic
  • New Topic