bhaskarreddy
EXCEPTIONS
1 Answer(s)      3 years and 9 months ago
Posted in : Java Interview Questions

View Answers

September 3, 2009 at 5:43 PM


Hi Friend,

You can use throws clause.For ex:

class MyException extends Exception {
public MyException(String msg){
super(msg);
}
}

public class Test {

static int divide(int first,int second) throws MyException{
if(second==0)
throw new MyException("can't be divided by zero");
return first/second;
}

public static void main(String[] args)throws MyException {
System.out.println(divide(4,0));

}
}

Thanks









Related Pages:
exceptions
exceptions  why we get compiletime exceptions(checkedExeption)? forEg:IOException,servletException
Exceptions - More
Java NotesExceptions - More Exceptions | Exception Usage | Exceptions - More Kinds of Exceptions There are many exceptions, but they can be put into two groups: checked exceptions and unchecked exceptions
how to deal with exceptions in servlet
how to deal with exceptions in servlet  plz give me the reply
Exceptions
Java NotesExceptions Exceptions | Exception Usage | Exceptions - More... that will catch it. You shouldn't try to catch most exceptions, but you should catch all exceptions that are caused by events which you have no control
Exceptions in java
Exceptions in java       Exceptions are used for handing errors and other exceptional events in Java programming language.Exception: Exceptions are abnormal or special conditions
exceptions in java - Java Beginners
exceptions in java  can any one explain exceptions with example... the normal flow of execution of a program. Exceptions are used for signaling...://www.roseindia.net/java/exceptions/ Thanks
Java Exception - Handle Exceptions in Java
Java Exception - Handle Exceptions in Java       Exceptions in Java...; Null Pointer Exception Null pointer exceptions are the most
JSP handle runtime exceptions
JSP handle runtime exceptions  How does JSP handle runtime exceptions?   Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting
Exceptions in RMI - RMI
Exceptions in RMI  During the execution of RMI program, the following exception is raised. Error.. java.rmi.ServerException : ServerRemoteException : nested exception is java.rmi.UnmarshalException : error unmarshalling  
How to solve the Hibernate Common Exceptions?
How to solve the Hibernate Common Exceptions?  How to solve the Hibernate Common Exceptions
interfaces,exceptions,threads
interfaces,exceptions,threads  SIR,IAM JAVA BEGINER,I WANT KNOW THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface.../interface.shtml   Exceptions Exception are such anomalous conditions
EXCEPTIONS-----1 - Java Interview Questions
EXCEPTIONS-----1  How To Handle The Exceptions With Out Using Try,Catch And Throws?I Want Region Plz Post Answer
Chapter 12. Exceptions
exceptions to inform the client of abnormal application-level conditions.... Application exceptions are not intended for reporting system-level problems..., and subclasses thereof are considered to be application exceptions
Core Java Exceptions - Java Beginners
Core Java Exceptions  HI........ This is sridhar .. Exceptions r checked exception and unchecked exception ........? Checked exceptions r at compile time and Unchecked exceptions r runtime? but Exception is Runtime
JSP handle run-time exceptions
JSP handle run-time exceptions  How does JSP handle run-time exceptions?   You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing
Java Exceptions Tutorials With Examples
Java Exceptions Tutorials With Examples       Exceptions in Java Exceptions... the execution of the program. Exceptions are the conditions or typically an event
Making Exceptions Unchecked - java tutorial,java tutorials
and Unchecked Exceptions in java and how to handle it. The Exception is a condition... since it is implicitly available in all java programs. The exceptions derived.... These exceptions are called 'Unchecked Exception'. Some of the common examples
Catching Normal Exceptions
Catching Normal Exceptions       The exceptions that are generated by methods are referred to as normal exceptions.  We have already learned that to catch an exception
Making Custom (User Defined) Exceptions
Making Custom (User Defined) Exceptions   ... Making Custom (User Define Exceptions) So far you would have been known, how to be handled the exceptions in java ======= So far you would have been known, how
What are Chained Exceptions?
What are Chained Exceptions in Java?   ... provides new functionality for chaining exceptions. Exception chaining (also... exception is caused by the first exception. Therefore chained exceptions help
Hi Friend ..Doubt on Exceptions - Java Beginners
Hi Friend ..Doubt on Exceptions  Hi Friend... Can u please send some Example program for Exceptions.. I want program for ArrayIndexOutOfbounds OverFlow Exception.. Thanks... Sakthi  Hi friend, Code
Catching and Handling Exceptions
Java Catching and Handling Exceptions       The various keywords for handling exceptions... the exceptions. These are try, catch and finally clause. The mechanism to catch
Catching Exceptions in GUI Code - Java Tutorials
In this section, we will discuss how to catch uncaught exceptions in GUI. Lets see... at java.awt.EventDispatchThread.run After printing the above exceptions... will catch all uncaught exceptions that are caused by the event dispatch thread
new to EJBs exceptions while excuting Client code - EJB
new to EJBs exceptions while excuting Client code  Hi i am new... then it is compiling fine can any one help me please.. i am posting the client code and the EXCEPTIONS here... thanks
Custom Exceptions
. Whenever we have declare our own exceptions then we call it custom exceptions
Exceptions in Java
Exceptions in Java       Introduction Exception is a run-time error which arises during... out of the memory, result in Run-time error. Why  Exceptions Occur
Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans.
application exceptions and system exceptions in entity beans, session beans... or examples about application exceptions and system exceptions in entity beans... Handling of exceptions thrown by a business method of a bean
Exception Usage
Java NotesException Usage Exceptions Exception Usage | Exceptions - More Common Exceptions The most common exceptions to catch are number conversion exceptions and I/O exceptions. Here are some common exceptions to catch
How to Throw Exceptions
How to Throw Exceptions in Java       Before catching an exception it is must to be thrown... the exceptions thrown by some methods so it insists us to handle them. We can also
Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.
the client's view of exceptions received from an enterprise bean invocation... of exceptions received from an enterprise bean invocation... clauses MAY include an arbitrary number of application exceptions
Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog
Given a list of responsibilities related to exceptions, identify...; Given a list of responsibilities related to exceptions, identify those... exceptions [BUSINESS exceptions] in the throws clauses of the methods
Exception Handling : Custom Exception
the Custom Exceptions(user defined exceptions). Custom Exception : Custom... inbuilt exceptions but sometimes application requires some meaningful exceptions to develop. So, we can create our own exceptions by extending Exception class
Exceptions Rethrowing with Improved Type Checking
Exceptions Rethrowing  with Improved Type Checking In this section, you will learn about the Java SE 7 exception rethrowing with improved type checking. Take a a look at the following code having improved type checking of Java
Java User-defined Exception
Java User-defined Exception In this tutorial, you will learn about the User-defined Exceptions. These custom exceptions actually all the programmer to handle errors in the applications with customized responses. It creates the java
What is AWT in java
, WindowClosed. Exceptions and Descriptions of AWT Package
Java ioexception
Java ioexception       Exceptions in java is the way of indicating the occurrence of abnormal condition... of  I/O problem has occurred. This is the general class of exceptions
Java Throw Built-in Exception
Java Throw Built-in Exception In this section we are discussing about throwing of built-in exceptions in Java. In Java throw and throws keywords are used to throw an Exception. throw keyword throws an exception forcibly that may use
Java Glossary Term - I
Java Glossary Term - I       Java ioexception Exceptions in java is the way of indicating the occurrence of abnormal condition in the program. Actually, these are objects
Java ?throw? Keyword
Java ?throw? Keyword       Exceptions are thrown to signal abnormal conditions that can often be handled...; www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml  
Exception handling in Objective-C
exceptions in the code and easier to maintain as well. To take support of exception handling make sure the -fobj-exceptions flag is turned
Exception Handling
Exception Handling       Exception, that means exceptional errors. Actually exceptions are used for handling errors in programs that occurs during the program execution
Null Pointer Exception
Null Pointer Exception        Null pointer exceptions are the most common run time  exception error arises during execution of java program. All values in Java
Example to show exception in java
class in java .Exceptions are the set of condition in Java to indicate... describes  how to use exceptions appropriately in your programs... number except 1 it will not give any exceptions. Download source code
Example to show Argument Exception in java
from Argument exception in java .Exceptions are the condition  in Java... describes  how to handle Argument exceptions appropriately in your programs

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.