Micro Focus QTP (UFT) Forums
Difference between error handling and exception handling - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Difference between error handling and exception handling (/Thread-Difference-between-error-handling-and-exception-handling)



Difference between error handling and exception handling - venkatbatchu - 11-10-2009

Hi All,
Could you please explain with some sort of examples.....
If possible please provide some test data also.


Thanks,
Venkat.Batchu


RE: Difference between error handling and exception handling - jsknight1969 - 11-10-2009

I'm not sure of the technical difference, but I believe they are just a difference in languages. VBScript/ASP is an Error object. Other languages that are object oriented (.NET, C++, Java) (3GL) use an exception object for errors.

VBScript example
Code:
on error resume next
a = 1/0
if err.number <> 0 then
  msgbox err.description
end if

VB.NET example
Code:
Try
  a=1/0
Catch (ex as exception)
  msgbox ex.message
End Try

C#
Code:
try
{
  a=1/0
}
catch (exception ex)
{
  msgbox ex.message
}

The exception is more powerful. It is also not dependent on the vague and often odd Microsoft Error codes to trigger a handle condition. For example, you can actually test for an exception of type System.IO.Exception instead of trying to case all the -214XXXXX error codes.

Hope this helps.


RE: Difference between error handling and exception handling - venkatbatchu - 11-10-2009

Hi All,
with some R&D and am giving some of my understandings
Please let me know wheter this one is right or not

Error Handling means:

Which means we might be knowing where the error will comes in such situation we can handle those errors

Exception Handling means:
We will not be knowing when errors will come but using recovery scenario's we will be showing some of exceptions and this will be triggered whenver this exception will throws...


Please correct me if am wrong...

Thanks,
Venkat.Batchu


RE: Difference between error handling and exception handling - rahul1234 - 11-10-2009

hi venkatbatchu,
As per me we use error handling for expected error behavior of the application. Like in Flight reservation application, we have to validate that "If user click on OK button on Login dialog then error message(in dialog box- Please enter agent name) should display", same for 3 character error message and blank password and wrong password. We know that system should display that type of error. But we have to run our script for that we use error handling through (recovery scenario).
And we use exception handling for dynamic change in our application. Like Fax order. We also used to perform it through Regular expression.
Please let me know if i am worong?
I am not 100% sure for my ans. I request Ankur and Saket to look on this. This is very nice question.


RE: Difference between error handling and exception handling - Saket - 11-11-2009

Error is an expected situation in your Script. For example, Consider a situation where you specified a divided by zero in your script logic, and the script throws an error. So you will need to handle this wherever your logic expects.
Where as exception is a runtime error that the AUT might encounter during the execution of your script.
For example you are trying to login into your application and application throws an error for database connectivity lost or something like Connection closed or license expired. These are exceptions which are unpredictable errors during runtime.

So in my opinion error handling is to put your logic to handle an expected error in your script and eception handling is to handle an unexpected error thrown by application /script at runtime.


RE: Difference between error handling and exception handling - sreekanth chilam - 11-11-2009

Hi ,

Here is the bottomline.

Predictable Errors --> Error handling ( By using "On Error Resume Next")
Unpredictable Errors --> Exception Handling (By using "[color]Recover Scenario Manager Wizard[/color]")


RE: Difference between error handling and exception handling - smitapawar610 - 12-11-2018

Exceptions and Errors fall into three categories: checked exceptions, unchecked exceptions, and errors.

Checked Exceptions

Checked by the compiler at compile time
Methods that throw checked exceptions must indicate so with throws which must propagate up the calling stack until the exception is handled
Checked exceptions require explicit catching with a catch block
These include exceptions of the type Exception, except for RuntimeException and its subtypes

Unchecked Exceptions

Not checked at compile time by the compiler
Occur during runtime due to programmer error (i.e. out-of-bounds, divide by zero, etc.) or system resource exhaustion
These do not have to be caught (as they are not checked, they only are known when they occur)
Methods may throw unchecked exceptions but do not have to indicate so in declaration
These are exceptions and subtypes of RuntimeException

Errors

Errors are typically unrecoverable and present serious conditions
Errors are not checked at compile time and do not have to be (but can be) caught or handled