aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes error thrown in a constructor.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "error thrown in a constructor.." Watch "error thrown in a constructor.." New topic
Author

error thrown in a constructor..

arivu mathi
Ranch Hand

Joined: Jun 26, 2006
Posts: 38
import java . io . * ;

class Q031 {
{


Q031()throws Exception{
try
{
throw new Exception ( ) ;
}
catch ( IOException e )
{
System . out . println ( e ) ;
}
}
}


public static void main ( String args [ ] ) throws Exception {
System . out . println ( " GodSmack " );
new Q031 ( );
}
}

why the above code is showing error?
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643

check code above it is error free.
Awais Sheikh
Ranch Hand

Joined: Jun 07, 2006
Posts: 48


just try this one. you are using extra brackets. Please check your code carefully.
arivu mathi
Ranch Hand

Joined: Jun 26, 2006
Posts: 38
now the code compiles fine but it's showing runtime error..why?
David Kennedy
Ranch Hand

Joined: Jan 22, 2006
Posts: 33
I think because you cant throw a general Exception and expect to catch
it with a narrower catch exception such as IOException


"There are only 10 types of people in the world: Those who understand binary, and those who don't"
prarthana reddy
Ranch Hand

Joined: Jul 24, 2006
Posts: 48
Because you are throwing an Exception but not handling it properly..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error thrown in a constructor..