Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
Exceptions - handle or declare rule
Neha Jane
Greenhorn
Posts: 5
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, I am trying to figure out why this piece of code which does not follow the handle-or-declare rule for exceptions, still compile
package com.neha.dumps; public class ThrowExcept{ static String s = ""; public static void main(String[] args) { try { new ThrowExcept().doStuff(); } catch (Exception ex) { s += "c1 "; } System.out.println(s); } void doStuff() { s += "t1 "; throw new NumberFormatException(); //Each method must either handle all checked exceptions by supplying a catch clause or //list each unhandled checked exception as a thrown exception. // but why this code works then? }}
Swastik Dey
Bartender
Posts: 2270
20
I like...
posted 13 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
I hope the following article helps
http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html
Look at section 11.2.5
Swastik
Neha Jane
Greenhorn
Posts: 5
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot, Swastik. I dont know what led me to believe that NumberFormatException is a checked exception
. Thanks again
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
rethrow exception
Exception question
"Handle or Declare" Rule for Checked Exceptions
Checked Exceptions are Checked by Compiler to see if they are Handled or Declared
Question on Catch or handle exceptions rule
More...