Exceptions Answers



Excercises

1) examine c():  String s = null;
                 int length = s.length();

c() catches npe
c() throws npe to b()
b() catches npe
b() throws npe to a()
a() catches npe
a() throws npe to main()
main() catches npe
crashing the program



2) examine copy(): int index = 0; index <= source.length;

c() caughes npe
c() throws re
b() catches re
b() throws re
a() catches e
a() throws e
main() catches npe
crashing program



3) examin copy(): return null;

c() caughes aioobe
c() throws aioobe
b() catches re
b() throws re
a() catches e
a() throws e
main() catches aioobe



4) no. a() throws Exception, but main() neither
   catches nor declares a throws clause for Exception

5) no. a() executes   throw e;   but doesn't declare
   a throws clause for Exception

6) yes. RuntimeExceptions are unchecked, and hence
   do not need to be caught or declared to be thrown
   in a throws clause