Forum Discussion

Gone2TheDogs's avatar
Gone2TheDogs
Occasional Contributor
4 years ago
Solved

Desktop Scripting - How to throw an error

Hello! I'm brand new here! Love this tool but I must convince my company based on a proof of concept. 

 

So, my simple question is, how do you throw an error based on your own test?

 

  GridCellValue = Aliases.Purchasing.frmPurchasingMenu.MdiClient.frmPoShipDateMaint.pnlData.tabMain.tpgTracking.RadGroupBox5.dgvTracking.wValue(0,2)  'row, column
  If GridCellValue <> "167 AAA Cooper" Then
    'throw an error  
  End If
  
  GridCellValue = Aliases.Purchasing.frmPurchasingMenu.MdiClient.frmPoShipDateMaint.pnlData.tabMain.tpgTracking.RadGroupBox5.dgvTracking.wValue(1,2)  'row, column
  If GridCellValue <> "1234567890" Then
    'throw an error  
  End If

 

  • 2 ways :

     

    - Javascript basis;

     

     throw Error("This is the message of the error")

     

    It will generate an exception and you can manage it in single endpoint with try .. catch pattern.

     

    Note: you don't have to make throw new Error()  because new is implicit.

     

    - TestComplete basis (not really throwing error but sort of);

     

    Log.Error("This is the message of the error")

     

     

     

2 Replies

  • BenoitB's avatar
    BenoitB
    Community Hero

    2 ways :

     

    - Javascript basis;

     

     throw Error("This is the message of the error")

     

    It will generate an exception and you can manage it in single endpoint with try .. catch pattern.

     

    Note: you don't have to make throw new Error()  because new is implicit.

     

    - TestComplete basis (not really throwing error but sort of);

     

    Log.Error("This is the message of the error")

     

     

     

    • tphillips's avatar
      tphillips
      Frequent Contributor

      For some additional information, the difference between throwing a Javascript error and using Log.Error() is that if you use Javascript's throw keyword you can catch those errors in a try... catch statement, which might be useful in some circumstances. Log.Error() can't be caught by a try... catch statement.