Assignments/Article By Silvia Scano

Difference Between Compile Time Errors and Runtime

Student Assignment


Published on 22, 2022

I strongly believe no developer or coder can claim he write whole code without encounter any single error . this blog illustrate the compilation error and run time error.

Compilation errors:

Compilation errors are the error that have catch by compile when execute code program such as
  • Java source file name mismatch
  • Improper casing
  • Mismatched brackets
  • Missing semicolons
  • Method is undefined
  • Variable already defined
  • Variable not initialized
  • Type mismatch: cannot convert
  • Return type required
  • Unreachable code

These errors are caught by the compiler and it throws a compilation error. Java compile not only tells us there is compilation error but it also tells us where it is giving the error

Runtime Error:

Apart from compilation errors, there is one more type of error, Runtime Error. This error occurs when we write the logic of the code incorrectly. We are the only ones who can find these types of errors. The compiler will not catch the,. For example:
  • Dividing any numeric value by zero produces runtime errors.
  • Accessing an array-out-of-bounds.
  • Passing invalid data e.g. passing a numeric value to the non-numeric field.
  • Passing invalid parameters/arguments to a method.
  • Multiple processes trying to access the same resource at the same time.
  • Trying to store an incompatible type value to a collection.
  • Insufficient space/memory error in threads (OutOfMemoryError)

Thus, only way to catch them by reviewing the code before executing it.

How to Handle Runtime Errors

In java, Runtime errors can be solved with the help of try-catch statements, and to do so, we have to put the code that can throw a runtime error in the try-catch statements. And throw exception

Types of Exceptions

Java defines several types of exceptions that relate to its various class libraries. Java also allows users to define their own exceptions. Types of exceptions shown below in the figure from

Student Assignment

The views expressed in this document are those of the author and do not necessarily reflect the position of the London School of Emerging Technology. View the detailed policy Disclaimer for Student and Personal Websites

Our Latest Blog

Java Programming

Java Basics for Beginners: A Step-by-Step Guide to Mastering Java Programming

Introduction to Java programming Java, a versatile and extensively utilised programming language, is popular among...
Read More
Entity Relationship Diagrams (ERD)

Entity Relationship Diagrams (ERD): A Comprehensive Guide

Introduction to Entity Relationship Diagrams (ERD) Entity Relationship Diagrams (ERD) are powerful tools used in...
Read More
Full Stack Java Development

From Novice to Pro: Navigating the World of Full Stack Java Development for Beginners

Introduction to Full Stack Java Development Full-stack Java Development} is a comprehensive approach to creating...
Read More