Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception/Does not compile/runtime error  RSS feed

 
Matthew Han
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anybody help me with these concepts? I am a little confused with them.

Thanks
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew,

Here is a link to The Java Really Big Index, it is a list of topics and links for Java documentation and also a list of tutorials for further reading.

Or here is a link specifically to the Oracle Tutorial on Exceptions.

Basically any method that can throw an Exception has to have that Exception caught or passed up to the caller of the present method so:

or to handle an Exception locally you need to have a try/catch block like this:

Les
Matthew Han wrote:Could anybody help me with these concepts? I am a little confused with them.

Thanks
 
Liutauras Vilda
Marshal
Posts: 4642
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew, welcome to the Ranch

Could anybody help me with these concepts? I am a little confused with them.

Do you have and could provide some particular examples which confuse you?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does not compile would describe a source file where the compiler finds syntax errors
runtime error is would be an error that happens when the compiled code is running
An exception is a type of runtime error
 
Matthew Han
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Les, I am still learning,
Thank you very much

Matthew
Les Morgan wrote:Matthew,

Here is a link to The Java Really Big Index, it is a list of topics and links for Java documentation and also a list of tutorials for further reading.

Or here is a link specifically to the Oracle Tutorial on Exceptions.

Basically any method that can throw an Exception has to have that Exception caught or passed up to the caller of the present method so:

or to handle an Exception locally you need to have a try/catch block like this:

Les
Matthew Han wrote:Could anybody help me with these concepts? I am a little confused with them.

Thanks
 
Matthew Han
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liutauras,
Thank you, I don't really have an example, but just confusion on those terms.



Matthew
Liutauras Vilda wrote:Matthew, welcome to the Ranch

Could anybody help me with these concepts? I am a little confused with them.

Do you have and could provide some particular examples which confuse you?
 
Matthew Han
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the great answers, so that means, an exception must be at runtime after compiling the code? This means the code will be or should be compile fine but at runtime, there will be an exception.

Norm Radder wrote:Does not compile would describe a source file where the compiler finds syntax errors
runtime error is would be an error that happens when the compiled code is running
An exception is a type of runtime error
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an exception must be at runtime after compiling the code

Yes. If there is an exception, it will be at runtime.

at runtime, there will be an exception.

No. It is not necessary that there be an exception.
 
Matthew Han
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Norm,
Sorry, I meant even there is an exception, the code still can compile, but at runtime, the exception will be thrown, right? I was wondering if the code could still compile.

Thanks again


at runtime, there will be an exception.

No. It is not necessary that there be an exception.
 
Campbell Ritchie
Marshal
Posts: 55722
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are actually three kinds of errors:-
  • 1: Breach of the language's syntactic rules. Usually shown by failure to compile.
  • 2: Breach of the language's semantic rules. Usually shown by exceptions. Some language features, e.g. generics, @Override annotation, attempt to replace Exceptions with compile‑errors.
  • 3: Logic errors. These are the most serious by far. The program runs, completes, and produces the “wrong” result.
  • An exception can only occur at runtime, so the code must compile before an exception is thrown, except in special circumstances when using an IDE.
     
    Campbell Ritchie
    Marshal
    Posts: 55722
    163
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the cow, whoever it was
     
    Campbell Ritchie
    Marshal
    Posts: 55722
    163
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    About half an hour ago, I wrote:. . . An exception can only occur at runtime, so the code must compile before an exception is thrown . . .
    Actually you can get Exceptions if you try to run the main method in a non‑existent .class file, or simliar; I am not sure whether you would call that runtime or not. The code might not have compiled, but most Exceptions occur in code which compiled successfully.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!