answersLogoWhite

0

Exception is a situation in Java wherein the system is behaving in a not-so-correct way or rather the system is behaving in an erroneous way. Exceptions are handled using try-catch blocks.

Ex:

try {

int x = 10/0;

} catch (Exception e) {

e.printStackTrace();

}

Here we are performing an illegal operation by dividing 10/0 which will throw a numeric exception which will be caught and handled inside the catch block

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Give an example of a procedural programming?

Popular one is C.


Give a simple example of a username?

welcome


What meaning by the terms 'member function'and give example?

In object-oriented programming languages, a member function is one which belongs to a class.


What is an exception With an example program explain how it is handled?

An exception is literally that: an exception. Exceptions are thrown when something that shouldn't happen does. For example, if you're trying to turn "Hi" into an Integer, you'll get a NumberFormatException (in Java.) If there is nothing in place to handle an exception, the program will crash. Try-catch blocks are used for exception handling within methods, and exception throwing is used to give out exceptions, or let a different method handle it. Example program (Java): class ex{ public static void main(String[] args){ String Strx = "5a"; int x = 0; try{ x += Integer.parseInt(Strx); }catch(NumberFormatException e){ // If Strx is not an Integer x += Integer.parseInt("5"); } System.out.println("The value of x is " + x); // The value of x is 5 } } Alternatively, you could remove the try-catch blocks, and simply write "public static void main(String[] args) throws NumberFormatException" in the 2nd line of the program.


Why are the indents necessary after the if and else statement?

Indents are not necessary for simple if statements: if (true) /* do something */ ; else /* do something */; However, when a statement is a compound statement, it's best to place the statement body on a separate line and indent it: if (true) { /* do something */ ; /* do something */ ; /* do something */ ; } else { /* do something */; /* do something */; } The indents help the reader; separating the controlling expressions from the compound statements and thus exposing the structure of the if statement itself.

Related Questions

Give an example of a procedural programming?

Popular one is C.


Give a simple example of a username?

welcome


Can you give me more example of simple sentences showing svc relationship?

example of svc


What is the core concept of marketing give you explanations with example?

give me answer of this question with example and simple word i am very thankful to you sir


What the meaning of unclassified and give the simple example for that.?

Unclasffied mails


Why they learn calculus?

To solve certain problems that can't be solved with simple algebra. To give just one simple example, find the maximum value of a certain function.To solve certain problems that can't be solved with simple algebra. To give just one simple example, find the maximum value of a certain function.To solve certain problems that can't be solved with simple algebra. To give just one simple example, find the maximum value of a certain function.To solve certain problems that can't be solved with simple algebra. To give just one simple example, find the maximum value of a certain function.


Can you give an example of a simple sentence using me?

She handed me the book.


What determines an information system is strategic give example?

its really simple


Can you give an example of a simple sentence using the word plants?

I have plants.


Can you give an example of a simple sentence using the word sincere?

She was sincere and honest.


Can you give an example of a simple sentence using the word accrue?

Accrue holiday


Give an example of a simple subject?

boy, girl, brother, sister