The Artima Developer Community
Sponsored Link

Java Answers Forum
Compiler vs. Run-Time Exceptions

2 replies on 1 page. Most recent reply: Feb 14, 2004 3:29 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Dave

Posts: 1
Nickname: davebrot
Registered: Feb, 2004

Compiler vs. Run-Time Exceptions Posted: Feb 9, 2004 2:59 PM
Reply to this message Reply
Advertisement
Are there some general rules one can follow to know when an error will be compile-time vs. run-time? Some examples are very obvious, but others are not.


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: Compiler vs. Run-Time Exceptions Posted: Feb 11, 2004 6:27 AM
Reply to this message Reply
> Are there some general rules one can follow to know when
> an error will be compile-time vs. run-time? Some examples
> are very obvious, but others are not.

Compile-time errors mean that you typed something in that was wrong. But run-time errors usually involve code that only causes problems in certain circumstances. For example

String userName = javax.swing.JOptionPane.showInputDialog(null, "Enter Your Name");
System.out.println(userName.toUpperCase());

If I forget to write javax.swing. before JOptionPane, that will cause a compile-time error since the compiler won't be able to find the class. (Another option is to use an import statement.)

As written, the code will work fine UNLESS the user closes the dialog or presses the Cancel button. That is a run-time exception. The code wasn't typed in wrong, but it needs code that will catch errors. Often, beginner examples leave out error-checking code to avoid the extra complexity.

I hope this helps.

tom

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Compiler vs. Run-Time Exceptions Posted: Feb 14, 2004 3:29 PM
Reply to this message Reply
Its simple as this.

If you get an error while you are invoking javac, then its a compile time error.

If you get an error while you are invoking java after a successful compile, then its a runtime error.

Flat View: This topic has 2 replies on 1 page
Topic: japplet vs jframe Previous Topic   Next Topic Topic: Connect from Java Application to Access DB

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use