http://www.technicalpage.net/search/label/SQL

>> Exception / Error in Java


Exception / Error in Java:

The test fails or stops the execution because of two reasons:
Exception  and
Error

Error:
This could be environmental , browser , server , hardware , access/permission , technical issues , networking problems, speed, Access problems etc. Tester has no control over these things, they can only report the issues.

Exception:
These are error in the code. These might be :
checked(compile time) or unchecked(run time)

Checked or Compile Time Exception:
This exceptions occur while writing the code or before execution. If any error is found, Java shows the error right away. 
Such as : spelling mistake , duplicate variable ,  closing bracket missing, closing curly bracket  missing , local variable not being initialized , missing of coma (,) , missing of statement ending semicolon, wrong format of coding , method not found when called etc.
Similarly below exceptions are also checked exception as you need to add "throws or try/catch" while writing the code if there is possibility of below exceptions,
IO Exception,
SQL Exception
File Not Found exception

Unchecked or RunTime Exception:
These exception occurs while the code is running. 
Such as :
WebElement not found,
Arithmetic Exception,
Array Index Out of Bound Exception
NullPointerException
TimeoutException
NoSuchElementException (Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@title='Search1']"} )
NoSuchFrameException  
java.lang.IllegalStateException : when you give wrong path for chrome driver OR when you pass nothing in sendKeys, such as sendKeys();

Note : Exception is the major class of other exceptions. So, in  "throws or try/catch" , you can use individual exception which could be one or many OR use Exception only which takes care of all other exceptions. See the section try/catch for detail.

User-Defined Exception:
Sometimes available Java built-in exceptions are not enough to describe the kind of exception we get/expect in our code. In such situations, we can create/define new exception called user-defined exception.

No comments:

Post a Comment