File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Checked Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checked Exceptions" Watch "Checked Exceptions" New topic

Checked Exceptions

rohith janga

Joined: Jul 18, 2011
Posts: 2
guys can any one clear this for me :

i have been trying to burn in the concepts of checked in checked exceptions we have to either declare or handle the exception the method is handling right? in that case if i do that the compiler shoudnt complain about the error while i am compiling

look at this:

package com.flowcontrol.examplw;

public class ThrowsDemo {
void throwone() throws IllegalAccessException {
System.out.println("Inside throwone");
throw new IllegalAccessException("demo");
public static void main(String args[])
catch (IllegalAccessException e)
System.out.println("Caught " + e);

in the above case iam trying to call a non static method in a static method i know that the compiler complains !!!. but why is it still complaining when i am handling it?
plese try to help me out?
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
The compiler is complaining because a static method main() is accessing an instance method throwone(). This is not allowed.
I agree. Here's the link:
subject: Checked Exceptions
It's not a secret anymore!