Nested try



Share on Google+Share on Google+

steffy gray
Nested try
1 Answer(s)      5 years and 7 months ago
Posted in : IDE Questions

Each time when i execute this code in eclipse i get different answers pl help me with this code

class Demo
static void nestedTry(String args[])
 int a = Integer.parseInt(args[0]);
 int b = Integer.parseInt(args[1]);
catch (ArithmeticException e)
System.out.println("Div by zero error!");
public static void main(String args[])
     try {
     catch (ArithmeticException e) 
    System.out.println("Need 2 parameters!");
View Answers

March 14, 2012 at 3:51 PM

Definitely, you will get different outputs. The output depends on your input values. After compiling the code, if you run the code with the following inputs:

java Demo 2 3, it will give output 0 , the try block of method is called which divides one value from other 2/3 whose result is actually a decimal value which is converted to int and gives 0.

java Demo 2 2, it will give output 1 , the try block of method is called which divides one value from other 2/2 and gives 0.

java Demo 3 2, it will give output 0 , the try block of method is called which divides one value from other 3/2 whose result is actually a decimal value which is converted to int and gives 1.

java Demo 2 0, it will give exception, the try block of method is called which passes the condition to catch block as an exception (cannot divided by 0) occurs and display the error 'Div by zero error!'.

If you will not input any number, 
java Demo, it will return ArrayIndexOutOfException: 0.

If you will input only one number,
java Demo 2 it will return ArrayIndexOutOfException: 1.

Finally always execute in any case.

For more information, visit the following link:

Nested Try Example


Related Tutorials/Questions & Answers:
Nested try
Nested try  Hi, In eclipse without providing input i am getting... explain me class Demo { static void nestedTry(String args[]) { try... static void main(String args[]) { try { nestedTry(args); } catch
Nested try
, visit the following link: Nested Try Example...Nested try  Each time when i execute this code in eclipse i get...(String args[]) { try { int a = Integer.parseInt(args[0]); int b
Nested Try-Catch Blocks
Nested Try-Catch Blocks       In Java we can have nested try and catch blocks. It means... of the catch statements succeeds, or until all of the nested try statements
Nested try catch
Nested try catch      ... be written in the try block.  If the exceptions occurs at that particular block then it will be catch by the catch block. We can have more than one try/catch
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... nested classes are: It is a way of logically grouping classes that are only used
nested loops
nested loops  please tell input to get the output: 12345 23456 34567 45678
try catch method in java
try catch method in java  try catch method in java - when and how should i use the try and catch method in Java ?   Please visit...://
Try it Editor
Try it Editor  Hello sir...actually i want to add an html,css & js editor like in w3 school try it editor 1.5....can you tell me how i can add it..pllz plzzz rppy soon
Nested Clases
Nested Clases  public class Nestclasses { a obj=new a(); public..."; System.out.println("hellwo in nested class"+i+ch); } } } class Outer..."); } } } /*Q:-Here I innner Class Constructor but its not call why i
try catch
try catch  why following code gives compile time error.please reply...=1;i<=3;i++) { System.out.println(i); try...); try { Thread.sleep(1000
nested for-loop
nested for-loop  hi.write a program that will prompt the user for a positive integer(num) and then display two triangles with num number of lines to represent the following patterns of asterisks. the input num must be validated
program to create nested tables
program to create nested tables  program to create nested tables
nested for loops
nested for loops  Hello all, I have created a program(gui) that allows a user to input time and minutes in textfields and then calculates... that the problem lies with my nested for loop which calculates all information
Nested classes: Examples and tutorials
Nested classes: Examples and tutorials       Nested classes Here is another advantage of the Java... within another class, such class is called a nested class. Inner classes can
Try Ruby
Try Ruby       Try out Ruby code in this site, by typing the ruby code then see the result. Read full Description
The nested class - Java Beginners
The nested class  Hi, What is nested class in Java? What is the benefits of nested class? Write examples of nested class. Thanks   .../java/n/java-nested-class.shtml Thanks
Inner Nested Classes
Inner Nested Classes       Non-static nested classes are slightly different from static nested classes, a non-static nested class is actually associated
GROUP BY IN NESTED QUERY  Hello Every One, Query to use GROUP BY CLAUSE IN NESTED QUERY SELECT STATEMENT in mysql database.If u know please help me.thanks
Java nested class example
Java nested class example  Give me any example of Nested Class.   Nested Class: Class defined within another class is called nested class. Nested class is divided into two parts- 1.Static 2.Non-static Static
Need help with nested queries
Need help with nested queries  Hello, Table1 has "id", "votes" columns. Table2 has "id", "Name" column. I need to retrieve Name and its corresponging Votes. I tried with nested queries but its confusing. Can anyone please help
Nested and Inner classes
Nested and Inner classes  What is the significance of Inner Classes and Static Inner Classes? or Why are nested classes used?   Hi Friend... a nested class. Inner class is a non static class declared inside another class.Non
Nested If Statement
Nested If Statement       In this section you will study about the Nested-if Statement in jsp. Nested If statement means to use the if statement inside the other if statement
Using Nested loops
Using Nested loops  How to use nested loops in java when I want to print the 10 multiples of numbers 2 to 15(in multiplication table)   public class MultiplicationTable{ public static void main(String[] args) { int
java try catch
java try catch  try{ return 1; }catch(exception e){ return 2; } finally{ Return 3; } What is the out put if any exception occurred
nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource  Hi, I am getting the following error while starting a web application: nested exception
try and finally block
try and finally block  hello, If I write System.exit (0); at the end of the try block, will the finally block still execute?   hii, if we use System.exit (0); statement any where in our java program
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch...; try{ x=a/b; }catch (Exception er.... Then to perform exception handling, we have used try and catch block where we have
Nested Loop - Java Beginners
Nested Loop  Hi, Can anyone tell me example of Nested loop in Java? Thanks   Hi friend,public class NestedExample{ public static void main(String[] args){ /** Print Pattern I */ System.out.println("
Nested Ajax--not getting output
Nested Ajax--not getting output  Hi everyone... I have two.jsp page from that , with the help of ajax i have called three.jsp. So, i have used DIV in my jsp pages . on button click,It gives me my desired answer. Same,in next
nested select tag
nested select tag  My requirement is as follows suppose combobox to select country whenever i select a country it will show corresponding states...;Select</option>"; try{ Class.forName("com.mysql.jdbc.Driver
Static Nested Classes
Static Nested Classes       A nested class that is declared static is called a static nested class. Memory to the objects of  any static nested classes are allocated


Advertisement null