Skip to main content

Exception Handling in java programming

 Exception Handling and types of exception handling in java programming


Exception handling in java programming

Exception handling means avoiding abnormal termination of the program.Different types of error occur in our program,such as user errors,logic errors or system errors.When an exception occurs, it makes further execution of the program impossible.Java offers an excellent exception

handling mechanism which is easy to understand and implement.Whenever an error occurs during the execution of a program,it throws an exception.If the exception is not handled properly,

the program execution  is terminated.

What is an exception handling mechanism in java?

Exception handling is a mechanism that enables programs to detect and handle errors before they occur rather than allowing them to occur and suffering the consequences.

Handling Exception In Java

 Exception handling in java is accomplished by using

 five keywords. try,catch,throw,throws and finally.

Java exception categorized into three types

  1. Checked exception —> Also known as  compile time exception
  2. Unchecked exception —> Also known as  runtime exception
  3. Errors

Some Example for the runtime exceptions are 

ArithmeticException ---> Errors that occur when dividing by zero

NumberformatException ---> converting string to integer

ArrayIndexOutOfBoundException ---> assigns an array size and the user

accesses beyond the size.

NullPointerException ---> Its an error that occurs when a string variable

is assigned null and an instruction is issued to print the string length.

All these exceptions are available in throwable classes.

This is available in the lang package.

lang package is the default package.

Advantages of exception handling in java


  • The separation of error-handling code from normal code
  • A logical grouping of error types
  • The ability to propagate errors up the call stack




Comments

Popular posts from this blog

Introduction to java programming-very important theory notes

Introduction to java programming what is java? Java is a high level object oriented computer programming language(OOPS). Java is a general purpose programming language used in computers and other applications. Java, an object-oriented programming language developed by Sun Microsystems under the leadership of James Gosling, Bill Joy, etc., is used today in many electronic devices such as web servers, computers, and mobile phones. Although it is mostly used for web programming, it is a multi-purpose programming language that can be used to do many other things. After Oracle bought Sun Microsystems in mid-2009, Java came under Oracle's control. (Wikipedia). What is a computer? A computer is an electronic device for storing and processing huge amounts of information. What is a computer program? A computer program is a set of instructions for a computer to perform a specific task. A computer cannot do anything by itself, if it wants to do something, it must get clear instructions, the i...

JAVA BUZZWORDS

     JAVA BUZZWORDS & H istory of the development of java java buzzwords explanation     Features of java is called as Java Buzzwords Platform independent —> Run on any Environment Object oriented concept(oops) —> Abstraction,Encapsulation,Inheritance and polymorphism Simple —>  No concept of pointers,explicit memory allocation, structures,operator overloading etc  Secure —> Secure for internet application (Raise  out of boundary exception in arrays and it is strong typed language) Robust —> Early checking of error it can achieved garbage collector, exception handling Portable  —> Java program written on one environment can be executed or implemented another environment Multithreading  —> Concurrent execution of several parts of same program at same time(This will improve CPU utilization) Distributed Application —> This are software that runs on multiple computers connected  to a network at ...

How to run java program using while loop

 Java program how to print Happy New Year in 10 times(using while loop) java buzzwords static keyword in java The AI ​​Revolution- Malayalam article step by step explanation Before writing Java code Install Jdk on your system and Set the path properly. Then type the Java code in the notepad and save it as a class name with the .java extension. Select the file type 'all file' while saving. Open cmd, Change the directory where the file is saved, using the cd command. Type javac class name.java then press the enter key, If you type java and give the class name, If there is no error in the program, the output will be generated. Observe the directory change using the cd command. Give the class name and watch it compile and run. How to run java program in notepad and cmd Where to code in Java and how it works? method 1 A text editor is required to write Java code The code can be run using the command prompt method 2  using an integrated development environment (IDE), such as Eclips...

Oops concepts in java

oops concepts in java with example programs Oops concepts in java Oops concept is very very important to make java programming easier and increase your programming skill.Four pillars of oops are Abstraction,Encapsulation,Inheritance,Polymorphism.Another technique to carefully understand in Java is classes and objects. This article covers very simple notes for Java programming beginners. What is object and class? The basics of oops is class and object Class is a blueprint which defines some properties and behaviors.  An object is an instance of a class which has those properties and behaviors attached.A class is not allocated memory when it is defined. An object is allocated memory when it is created Class and object —> object is defined as real word entities .Object consists of property and some task Class is a blueprint that object follows, Class  consists of many number of objects Four pillars of oops are Abstraction   —> Means showing only essential parts and hi...

Command Line Arguments In Java

Command Line Arguments In Java No input statement needed in the program itself. we can pass the input as an argument while running the program. Sometimes you will want to pass information into a program when you run it. This is accomplished by passing command line arguments to main function. To access the command line arguments inside a java program is quite easy are stored as string in string array passed to main function. Example program of command line arguments in java class CommandLineExample {    public static void main(String args[]) {    System.out.println("\nMy first input is  :"+args[0]);    }    }    Addition of two numbers in java using command line arguments  Example:write a program add two integer number    class AddCommandLine { public static void main(String args[]) { int num1=Integer.parseInt(args[0]); //type cast int num2=Integer.parseInt(args[1]); //type ...

Keywords in java programming

Keywords in java programming Keyword is a predefined word given by the compiler which has some specific task. Keywords also known as reserved word. All the java technology keywords are lower case . Java programming has a richer set of keywords than C language or C ++ language. Some java keywords are import —>In java programming implementing classes and methods import the packages that purpose using the keyword import. class —> In order to create a class we have use the keyword class to see an example written using the class keyword ) this —> This keyword is used to represent the method belongs to particular current object Super —> It can used in inheritance concept extends —> Also used in inheritance concepts. Accessing methods one class to another class that can done by extends keyword package —> In java there will be package which consists of number of classes and interfaces in order to access that package, using the key word package return —> Return key wor...

Naming Convention In Java

Naming Convention In Java-camel case example Naming Conventions are rules to be followed by giving a name to the identifier.Identifiers are program elements(such as class,object,variable,method so on ).For building software you should follow this rule to make your code look good, more efficient and more readble.Java has certain rules for naming identifier. This are given below Digit, letters, underscore or currency symbols( £, €, $ ) are allowed                The first letter of any identifier cannot be a digit An identifier name must not be a reserved words or keywords Java follows camelCase rule what is camelcase rule? CamelCase is a way to separate the words in a phrase by making the first letter of each word capitalized and not using spaces (ex :- MyFirstJavaClass) Class name —> should begin with a capital letter(In a single word) If it is multiple words, the first letter of every word begins with a capital letter. Ex :- class Stu...