Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions java question on exception

Have Programming Question? Ask it here!
 
 
 


priyanka sobani
java question on exception
2 Answer(s)      a year and 7 months ago
Posted in : Java Interview Questions


can we use inbuilt exception variable with throw keyword in java


Advertisement
View Answers

January 9, 2013 at 4:12 PM


The above code can also be written as follows :

public class Test
{
   ArithmeticException ae;
   public int  divide(int numerator,int denominator)
    { 
       if(second==0)
          {
             throw ae;             
          }       
       return numerator/denominator;
    }
   public static void main(String[] args) 
    {
       Test test = new Test();
       test.ae = new ArithmeticException("Second Number must not be zero");

            int result = test.divide(4, 0);
            System.out.println(result);        
    }
}


January 9, 2013 at 1:23 PM


hi friend, I think we can use the inbuilt exception variable with throw keyword in java.

I hope following sample code will be helpful for you.

public class Test
{
   static ArithmeticException ae;
   static int  divide(int first,int second)
    { 
       if(second==0)
          {
             throw ae;
          }        
       return first/second;
    }
   public static void main(String[] args) 
    {
       ae = new ArithmeticException("Second Number must not be zero");
       try
        {
            int result = divide(4, 0);
            System.out.println(result);
        }
      catch (Exception e) 
        {
           //e.printStackTrace();
           System.out.println(ae);
           //System.out.println(e);
        }
    }
}


Related Tutorials/Questions & Answers:
java question on exception
java question on exception  can we use inbuilt exception variable with throw keyword in java
Question on Checked Exception
Question on Checked Exception   why checked exception force to put try and catch block ? Please send me answer
Advertisements
Exception Java
Exception Java  Hi, What are the Exception Java? Thanks   Hi, Read it at Java Exception. Thanks
Java exception
Java exception  What happens if an exception is not caught
Java exception
Java exception  Can an exception be rethrown
Java Exception
Java Exception  Which is superclass of Exception
java exception
java exception   define an exception called no match exception tat z... { public static void main(String[] args) throws Exception { String z="Hello"; if(!z.equals("India")){ throw new Exception
Java exception
Java exception  What is the difference between Checked and Unchecked exception
Java exception
Java exception  What is the difference between exception and error
Java Exception
Java Exception  Explain about checked and unchecked Exceptions... this exception will be caught by a well-written application and will also prompt... to the constructor. Well in this case the exception could be caught by the application
Java Exception
Java Exception  What are monitors
exception in java - Java Beginners
exception in java  exception in java
Java Exception
Java Exception  What are Chained Exceptions
Java exception
Java exception  What is NullPointerException and how to handle
Java exception
Java exception  Can try statements be nested
Java Exception
Java Exception  What is the purpose of finalization
Java Exception
Java Exception  Why Runtime Exceptions are Not Checked
Java Exception
Java Exception  What is ?Resource leak
Java Exception
Java Exception  Why Errors are Not Checked
Java Exception
Java Exception  Can a catch block exist without a try block
Java Exception
Java Exception  If I write System.exit (0); at the end of the try block, will the finally block still execute
exception in java
exception in java  StringIndexOutOfBounds Exception in flames program   Hi Friend, We have providing you a program. Try it: import java.util.*; public class FlamesProgram{ static String name1 = ""; static
Exception - Java Interview Questions
Exception in Java programming  What is Exception?  Chained Exception in JavaChained Exception in Java, this is a new in release 1.4..., and these exception can be caused by another exception. Exceptions in Java
Exception - Java Beginners
://www.roseindia.net/java/java-exception/index.shtml Thanks... (inclusive), you want to throw your own exception. This means you will have to create your own exception class called NotCorrectAgeException and The main
Java exception handling
Java exception handling  what are the constraints imposed by overriding on exception handling
null pointer exception in java
null pointer exception in java  What is null pointer exception in Java and when it occurs? Show it with an example.Thanks!   Java Null Pointer Exception
Java Exception - Java Beginners
Java Exception  Why we are using throws in the java program even if we have try...catch block? If throws will throw the exception then who will catch... links: http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml
java exception handle
java exception handle  How error can be handled in the exception class?? can we handle fatal error in java
exception in java - Java Beginners
exception in java  exception in java  Hi Friend, Exceptions are the errors that occur during the execution of the program. Exceptions...: http://www.roseindia.net/java/exceptions/ Thanks
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Java exception handling
Java exception handling  How does a try statement determine which catch clause should be used to handle an exception
Exception - Java Beginners
What is Exception in Java  What is the Exception that occurs while running the application in Java
Java exception handling
Java exception handling  How does a try statement determine which catch clause should be used to handle an exception
Java exception handling
Java exception handling  What is the catch or declare rule for method declarations
Java exception handling
Java exception handling  What is the difference between throw and throws keywords
Exception - Java Beginners
Chained Exception in Java  What is the Chained Exception in Java?  Chained Exception in JavaChained Exception in Java, this is a new... of exceptions, and these exception can be caused by another exception.Exceptions in Java
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported. 2.) It uses primitive data type. 3.) static method can be called without creating instances
java Exception - Java Beginners
java Exception  Hello sir ,Here Exception in thread "main" java.lang.NoClassDefFoundError: bitwisedemo1/java Help me /** * Author@sushant savant a=64,I=a<<2 find I using Bitwise Left shift * */ public
Question Java>?
Question Java>?  **ï??· Create a new class called Bank and in the main method use class Account (lab 4) to create an array of 10 accounts. ï??· Enter data for all accounts (account number,name, balance). ï??· Add
check null exception java
check null exception java  check null exception java - How to check the null exception on Java?   The null pointer exception in java occurs... on it. See the example null pointer exception
Exception Handlerin java..
Exception Handlerin java..  can a catch block accept multiple argument and return type?? please tell with explaination
Java sql Exception
Java sql Exception  difference between sql exception class and sql warning class
Java exception class
Java exception class  What classes of exceptions may be caught by a catch clause
Java exception handling
Java exception handling  Does the order of placing catch statements matter in the catch block
Java exception handling
Java exception handling  What classes of exceptions may be caught by a catch clause
Java exception handling
Java exception handling  What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement
java question
java question   Create a class called Complex to perform arithmetic operations with complex numbers. 1- Use double variables to represent the fields of the class. 2- Provide a no-argument constructor with default values in case
java question :)
java question :)  write java program to use vector in ArrayList with add, remove,sort   import java.util.Vector; public class... Element MUAYAD"); vc.add("Vector Element JAVA"); vc.add("Vector Element
Advertisements
 

 

 

DMCA.com