wood burning stoves 2.0*
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
Author

Checked Exceptions

rohith janga
Greenhorn

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 exceptions....so 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[])
{
try
{
throwone();
}
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.
 
wood burning stoves
 
subject: Checked Exceptions
 
Similar Threads
Exception Handling
exception problem
Exception
Exception Problem
Exception