wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JavaCaps #60 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaCaps #60" Watch "JavaCaps #60" New topic
Author

JavaCaps #60

Yuki Cho
Ranch Hand

Joined: Apr 18, 2001
Posts: 31
hi there,
Can you please tell me why is the following code gives a compilation error?
Thanks,
Yuki
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
Usha Vydyanathan
Greenhorn

Joined: Jan 03, 2001
Posts: 17
Hi,
Method signature should include throws clause.
static void throwMethod() throws IllegalAccessException
{}
Usha
Yuki Cho
Ranch Hand

Joined: Apr 18, 2001
Posts: 31
Thank you Usha, i got it now.
-Yuki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaCaps #60
 
Similar Threads
Do Static methods throw exceptions?
Exception doubt
Compile Error
throw an Exception....
Exception Q?