0% found this document useful (0 votes)
4 views5 pages

Selenium 6

Uploaded by

prakashraut0508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Selenium 6

Uploaded by

prakashraut0508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Selenium

Errors and Exception:-

Throwable Class

Errors Exception

Errors : - Error refers to an illegal operation performed by the user which results in the abnormal working of the program.
Programming errors often remain undetected until the program is compiled or executed. Some of the errors
inhibit the program from getting compiled or executed. Thus errors should be removed before compiling and
executing. It is of three types:
•Compile-time
•Run-time
•Logical
Exeption:-
An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e at run time,
that disrupts the normal flow of the program’s instructions. In Java, there are two types of exceptions:

1.Checked exceptions.
2.Unchecked exceptions

1.Checked Exception:-
These are the exceptions that are checked at compile time. If some code within a method throws a
checked exception, then the method must either handle the exception or it must specify the exception using
the throws keyword.

2.Unchecked Exception :-
These are the exceptions that are not checked at compile time.
Errors Exceptions

We can recover from exceptions by either using try-catch block or


Recovering from Error is not possible.
throwing exceptions back to the Errorsthe The programoccurcaller.

All errors in java are unchecked type. Exceptions include both checked as well as unchecked type.

Errors are mostly caused by the environment in which program is


Program itself is responsible for causing exceptions.
running.

Errors can occur at compile time as well as run time. Compile Time:
All exceptions occurs at runtime but checked exceptions are known
eg Syntax Error
to the compiler while unchecked isnot.
Run Time: Logical Error.

They are defined in java.lang.Error package. They are defined in java.lang.Exception package

Examples : Checked Exceptions : SQLException, IOException


Examples : java.lang.StackOverflowError,
Unchecked Exceptions : ArrayIndexOutOfBoundException,
java.lang.OutOfMemoryError
NullPointerException, ArithmeticException.
How to handle a Exception in java :-

We handle the exception in Java by using Try and Catch Block.

Java try block

Java try block is used to enclose the code that might throw an exception. It must be used within the method.
If an exception occurs at the particular statement in the try block, the rest of the block code will not execute. So, it is
recommended not to keep the code in try block that will not throw an exception.

Syntax:-
try
{
block of code which can throw exception
}
catch(ArithmeticException e) //exception to be handeled
{
Statement/ code to be executed when the exception occurs
}

You might also like