Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site.... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Assignments/Article By Jakub Lisowski

Compile-Time Exceptions and Runtime Exceptions in Java

Student Assignment

Compile-Time Exceptions and Runtime Exceptions in Java

Published on June 16, 2022

Compile-Time Exceptions

Compile-time errors are errors that happen when we use the incorrect syntax or semantics of any programming language. The compiler will then throw compile-time errors at us. Until all of the program’s errors are fixed, the compiler won’t allow it to execute.

Characteristics of Compile-Time Exceptions:

  • Early identification of potential issues: By detecting exceptions at compile-time, developers can address them before executing the code
  • Compiler ensures handling or declaration: The Java compiler enforces that all checked exceptions are either caught and handled or declared to be thrown, reducing the likelihood of unhandled exceptions slipping through

Example of Compile-time error

  1. int main()
  2. {
  3.     int a=20;
  4.     printf(“The value of a is : %d”,a):
  5.     return 0;
  6. }

In the above code, we have tried to print the value of ‘a’, but it throws an error. We put the colon at the end of the statement instead of a semicolon, so this code generates a compile-time error.

Runtime Exceptions

The Errors that happen during execution and after compilation are known as runtime errors. Runtime mistakes include, but are not limited to, division by zero. Since the compiler does not flag these problems, they are difficult to find.

Characteristics of Runtime Exceptions:

  • Not checked by the compiler: Unlike compile-time exceptions, the Java compiler does not verify the handling or declaration of runtime exceptions, providing more flexibility to the programmer.
  • Caused by logical errors or unexpected conditions: Runtime exceptions are usually a result of issues such as invalid input, improper usage of APIs, or unexpected program states.

Example of runtime error

  1. int main() 
  2.     int a=20; 
  3.     int b=a/0; // division by zero 
  4.     printf(“The value of b is : %d”,b): 
  5.     return 0; 

In the above code, we try to divide the value of ‘b’ by zero, and this throws a runtime error.

Summary

Compile-time and Runtime are the two programming terms used in software development. Compile-time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running. Both the compile-time and runtime refer to different types of error.

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

Beyond the Buzz: How Prompt Engineering is Quietly Reshaping the Modern Workplace

Beyond the Buzz: How Prompt Engineering is Quietly Reshaping the Modern Workplace

The future of work isn’t about being replaced by AI, it’s about learning how to...
Read More
What is GPT Understanding Generative Pre-trained Transformers Mayur Ramgir

What is GPT? Understanding Generative Pre-trained Transformers

In the world of artificial intelligence (AI), a family of models known as GPT has...
Read More
How to Become an AI-Powered DevOps or Cloud Engineer in 2025

How to Become an AI-Powered DevOps or Cloud Engineer in 2025

The technology landscape is rapidly evolving, and the fusion of artificial intelligence with DevOps and...
Read More