This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaCaps #60" Watch "JavaCaps #60" New topic

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?
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
public static void main(String args[]) {
try {
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
Usha Vydyanathan

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

Joined: Apr 18, 2001
Posts: 31
Thank you Usha, i got it now.
I agree. Here's the link:
subject: JavaCaps #60
It's not a secret anymore!