File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception in main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception in main" Watch "Exception in main" New topic

Exception in main

Mauro Mazzucco
Ranch Hand

Joined: Apr 26, 2013
Posts: 32

Why this code compiles fine?
Main is throwing a Exception and noone catchs it, why the compiler doesnt complain?
Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 178

It's caught by JVM..

Konstantinos Alvertis

Joined: May 05, 2013
Posts: 11

Your code compiles fine . ( You don't have any syntax error etc ...)

With the

you declare that main method may throw an Exception.

In order to throw the exception add throw new Exception();

As Ramesh said the exception are caught at Runtime by JVM.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Recently discussed in this topic.

[Asking smart questions] [About Bear] [Books by Bear]
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
A related one at - What does it mean when the main method throws an exception?


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
M Shareef

Joined: Jun 10, 2012
Posts: 6

Your code is fine it is printing the "hi" to the console.

jQuery in Action, 3rd edition
subject: Exception in main
It's not a secret anymore!