java exception handling
hi while i am compailing the program given below i am getting an error please help me as soon as possible
import java.io.*;
class insufbal extends Exception
{
public insufbal(String str)
{
super(str);
}
}
public class bank
{
private int acc_id;
int wd_amt;
private String acc_name;
private double acc_bal;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public bank()
{
acc_id=0;
acc_name="";
acc_bal=0.0;
}
public void init()
{
String temp;
try
{
System.out.println("enter the account number");
temp=br.readLine();
acc_id=Integer.parseInt(temp.trim());
System.out.println("enter the account holder name");
acc_name=br.readLine();
System.out.println("enter initial account balance");
temp=br.readLine();
acc_bal=Integer.parseInt(temp.trim());
}
catch(IOException ie)
{
System.out.println(ie.getMessage());
}
}
public void deposit()
{
String temp;
try
{
System.out.println("enter the deposit amount");
temp=br.readLine();
acc_bal+=Double.parseDouble(temp.trim());
}
catch(IOException ie)
{
System.out.println(ie.getMessage());
}
}
void withdraw() throws insufbal
{
String temp;
System.out.println("Enter the withdrawl amount");
temp=br.readLine();
wd_amt=Integer.parseInt(temp.trim());
if(acc_bal>wd_amt)
{
acc_bal=acc_bal-wd_amt;
}
else
{
insufbal insb=new insufbal("insuficient balance inyour account");
throw insb;
}
}
public void show()
{
System.out.println("\n Account Details");
System.out.println("------------------");
System.out.println("Account number:"+acc_id);
System.out.println("Ac_holder name:"+acc_name);
System.out.println("Balance:"+acc_bal);
}
public static void main(String args[])throws IOException
{
bank b=new bank();
b.init();
b.deposit();
b.show();
try
{
b.withdraw();
}
catch(insufbal insb)
{
System.out.println(insb.getMessage());
}
b.show();
}
}
View Answers
Related Tutorials/Questions & Answers:
Java exception handlingJava exception handling what are the constraints imposed by overriding on
exception handling Exception Handling - Java BeginnersException Handling hi,can u pls make me understand d clear cut difference between throw n throws keyword...
n how can we make our own
exception..i... want to force an
exception then we use throw keyword. the throw keyword is used
Advertisements
Exception Handling in javaException Handling in java what is advantage to catch smaller
exception first and then normal
exception. I mean we normally catch SQLException first and then
Exception.
Hi,
The exceptions should be from
Java exception handlingJava exception handling How does a try statement determine which catch clause should be used to handle an
exception Java exception handlingJava exception handling How does a try statement determine which catch clause should be used to handle an
exception exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling exception handlingexception handling what is the information of
exception handling?
Have a look at the following link:
Java Exception Handling Java exception handlingJava 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 exception handlingJava exception handling Does the order of placing catch statements matter in the catch block
exception handling exception handling Give the
exception hierarchy of
Java.
Please visit the following links:
http://www.roseindia.net/
java/
java-
exception/
exception-java.shtml
http://www.roseindia.net/
java/exceptions/
exception Java null pointer exception handling Java null pointer
exception handling What is a java.lang.NullPointerException? Why do we use this
exception class and when it occurs in any
java... pointer
exception handling
What is
Java NullPointerException? In
Java exception handlingexception handling could you please tell me detail the concept of
exception handling exception handlingexception handling What is an
exception and what are the advantages of
exception handling mechanism.
Java Exception
Exception are the runtime errors.
Advantages:
1)
Exception provides the means to separate
java Exception handling - Java Beginnersjava Exception handling what is the difference between throw... an
exception manually where as throws is used in the case of checked exceptions to re-intimate the compiler that we have handled the
exception.
For more information
Exception handling in Java Programming ExamplesException handling in
Java Programming with many Examples
In this section we will explain you about the
exception handling in
Java and
teach you how.... In this section we are presenting many
examples of
exception handling in
Java Exception handling in Java Programming ExamplesException handling in
Java Programming with many Examples
In this section we will explain you about the
exception handling in
Java and
teach you how.... In this section we are presenting many
examples of
exception handling in
Java Java : Exception HandlingJava :
Exception Handling
In this section we will discuss about
JAVA Exception Handling with
simple example.
Exception Handling :
An
exception... by
java runtime and also generates error message
,which is displayed
java exception handling - Java Beginnersjava exception handling hi while i am compailing the program given below i am getting an error please help me as soon as possible
import java.io.*;
class insufbal extends
Exception
{
public insufbal(String str)
{
super
Exception Handling in Java occurred
in the program.
For more details about
exception handling click on the following links
Exception Handling in
Java
Example to show
exception handling in
java
User Defined
Exception
List of
Java Exception
Unhandled
exception handlingexception handling can you explain how to handle the
exception in
java with picture representation
Exception handling in javaException handling in
java
We are going to discus about
Exception handling in
java.
Java program many provides
exception. We are handle of error in program when during execution in a program .we are
generate of
exception try() block
Exception HandlingException Handling wrtie a
java program to enable the user to handle any change of divide by zero
exception.
Please visit the following link:
http://www.roseindia.net/
java/exceptions/how-to-throw-exceptions.shtml
exception Handlingexception Handling write a program in
Java to display the names and roll numbrs of students. Initialize respective array variables for 10 students. Handle ArrayIndexOutOfBoundsException, so that any such problem doesn't cause
Exception HandlingException Handling create an
exception class, which thros an
exception if operand is non-numeric in claculating modules. ( Use command line arguments
Exception handlingException handling
exception are occur at run time but when we connect to the database errors will come at compile time why
exception handling mechanismexception handling mechanism Explain
Java's exception handling...://www.roseindia.net/
java/exceptions/exception.shtml
http://www.roseindia.net/
java/exceptions/catching-and-
handling-exceptions.shtml
exception handlingexception handling a program to accept only three integer values as command line arguments. Print the values entered by the user. Handle ArrayIndexOutOfBoundsException and NumberFormatException by providing the applied messages
Exception HandlingException Handling Hi, I really appreciate the help I have gotten,I... for the student. Create an
Exception class named GradeException that contains.... In the application, throw a Grade
Exception if the user does not enter a valid letter
Exception HandlingException Handling Hi, I really appreciate the help I have gotten,I... for the student. Create an
Exception class named GradeException that contains.... In the application, throw a Grade
Exception if the user does not enter a valid letter
array in exception handlingarray in
exception handling write
java program to declare and initialize an array with the number given, 4,6,3,0,5,5,12 then the program will ask user to enter indexs number to display its value .using
exception handling Using throw keyword in exception handling in Core JavaDescription:
Core
Java Throw Function is used for throwing the
exception...
exception need to be thrown from the
calling method.
Code for
Java Throw
Exception Handling:ADS_TO_REPLACE_1
package exceptionh;
import java.io.*;
class