Exception

CAn we define new Exception.that is user defined exception ?
IF a statemetn is error then it throws some exception,or it throw some exception and catch it my the mehtod.
cam we decalare our own exception and can we catch it?

for the most of the exceptions thrown in java, if you are using try-catch block you may write catch (exception e)
you do not have to define exceptions in to the try-catch blocks. Of course, if you know which exception will occur you can define but it is not rule for java to define the exception.
--hope it helps
--scientist

You mention yourself that you hope your input helps, why block it by proposing an answer?

Here is some text from the book "Thinking in Java" which should clarify some things:

To create your own exception class, you?re forced to inherit from an
existing type of exception, preferably one that is close in meaning to your
new exception (this is often not possible, however). The most trivial way
to create a new type of exception is just to let the compiler create the
default constructor for you, so it requires almost no code at all:

When the compiler creates the default constructor, it which automatically
(and invisibly) calls the base-class default constructor. Of course, in this
case you don?t get a SimpleException(String) constructor, but in
practice that isn?t used much. As you?ll see, the most important thing
about an exception is the class name, so most of the time an exception like
the one shown above is satisfactory.
Here, the result is printed to the console standard error stream by writing
to System.err. This is usually a better place to send error information
than System.out, which may be redirected. If you send output to
System.err it will not be redirected along with System.out so the user
is more likely to notice it.
Creating an exception class that also has a constructor that takes a String
is also quite simple:

The added code is small?the addition of two constructors that define the
way MyException is created. In the second constructor, the base-class
constructor with a String argument is explicitly invoked by using the
super keyword.

The stack trace information is sent to System.err so that it?s more likely
it will be noticed in the event that System.out has been redirected.

The output of the program is:

Throwing MyException from f()
MyException
at FullConstructors.f(FullConstructors.java:16)
at FullConstructors.main(FullConstructors.java:24)
Throwing MyException from g()
MyException: Originated in g()
at FullConstructors.g(FullConstructors.java:20)
at FullConstructors.main(FullConstructors.java:29)

You can see the absence of the detail message in the MyException
thrown from f( ).
The process of creating your own exceptions can be taken further. You can
add extra constructors and members:

A data member i has been added, along with a method that reads that
value and an additional constructor that sets it. The output is:

Throwing MyException2 from f()
MyException2
at ExtraFeatures.f(ExtraFeatures.java:22)
at ExtraFeatures.main(ExtraFeatures.java:34)
Throwing MyException2 from g()
MyException2: Originated in g()
at ExtraFeatures.g(ExtraFeatures.java:26)
at ExtraFeatures.main(ExtraFeatures.java:39)
Throwing MyException2 from h()
MyException2: Originated in h()
at ExtraFeatures.h(ExtraFeatures.java:30)
at ExtraFeatures.main(ExtraFeatures.java:44)
e.val() = 47

Since an exception is just another kind of object, you can continue this
process of embellishing the power of your exception classes. Keep in
mind, however, that all this dressing-up might be lost on the client
programmers using your packages, since they might simply look for the
exception to be thrown and nothing more. (That?s the way most of the
Java library exceptions are used.)

Thanks for the big comment barrel But my proposed answer also comes from the Book "Java Programmimg :From the Beginning" and I have just completed highly recommended course in java using that book so, I have some knowledge of what is a good answer or good comment.
--scientist

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application.
For the purposes of this article, I will be u…

Introduction
This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …

Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…