Explain try and catch exception in java, JAVA Programming

Assignment Help:

Explain try and catch exception in java?

Why use exceptions instead of return values?
1. Forces error checking
2. Cleans up your code through separating the normal case from the exceptional case. (The code isn't littered along with a lot of if-else blocks checking return values.)
3. Low overhead for non-exceptional case

Traditional programming languages set flags or return bad values such as -1 to denotes problems. Programmers frequent don't check these values.

Java throws Exception objects to denotes a problem. These cannot be ignored.
try-catch
try-catch
public class HelloThere {

public static void main(String[] args) {

try {
System.out.println("Hello " + args[0]);
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Hello Whoever you are.");
}

}


Related Discussions:- Explain try and catch exception in java

Help, Are you real? I dont want to get help from a computer

Are you real? I dont want to get help from a computer

What is synchronous messaging, Synchronous messaging involves a client that...

Synchronous messaging involves a client that waits for the server to respond to a message. So if one end is down the whole communication will fail.

Object and Instance, What is the difference between instance and object of ...

What is the difference between instance and object of a class? Few says both are same, then why java kept both the words for same thing?

I want crime management website, I want Crime Management website Project...

I want Crime Management website Project Description: It is a web based project build in J2EE as front end and Oracle as back end for peoples so they will register complaints

Difference between boolean & operator and && operator, How can we define th...

How can we define the difference between the Boolean & operator and the && operator ?

Sum of six digits, How do I write a java program that enters a six digit nu...

How do I write a java program that enters a six digit number and takes the sum of the six digits?

Answer, a program to find the area under curve y=f(x) between x=a and x=b,i...

a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b

Object and Instance, What is the difference between instance and object of ...

What is the difference between instance and object of a class? Few says both are same, then why java kept both the words for same thing?

What is object oriented programming explain with an example, What is Object...

What is Object Oriented Programming explain with an example? In Java everything is an object or a class (or a piece of one or a collection of various). Objects send messages t

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd