File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checked Exceptions

 
rohith janga
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic