18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Exception Handling

aspatel80aspatel80 Members
edited November -1 in Sahi - Open Source
Hi Team,

Can anybody tell me how to handle exceptions on SAHI. I want to avoid various exceptions coming up in SAHI and divert them into my scripts so that I can look at them at the spot and make necessary corections.

Regards,
Ashvin.

Comments

  • narayannarayan Administrators
    Ashvin,
    Have a look at this:
    http://sahi.co.in/w/exception-handling
    (I just added it)
    Regards,
    Narayan
  • Hi Narayan,

    Thanks for the post :)

    Regards,
    Ashvin.
  • Hi Narayan,

    I want to show the exception occured in my alert box. Can you tell me how can I do that.

    Regards,
    Ashvin.
  • narayannarayan Administrators
    try{
      _click(_link("does not exist"));
    }catch(e){
      $message = e;
      _alert($message); 
       // Note _alert(e) will not work since it is a variable on the proxy 
       // and we are wanting it be alerted by the browser.
       // So we assign it first to a $ variable and then pass it to _alert.
    }
    
  • hi,
    when i tried this code it got executed till the corrective action, but i got the error for the last line i.e
    _logException(e) and playback failed message came.I got the error like this
    "JSERROR Cannot convert NaN to Javalang integer"



    try
    {
    _click(_link("does not exist"));
    }
    catch(e)
    {
    $message = "this button does not exist";
    _alert($message);
    _click(_link("Log Off")); // Corrective action
    _logException(e); // Logs the exception, but does not fails,
    }


    How to resolve this?
  • I get exactly the same error too.

    Donna
  • narayannarayan Administrators
    Looking at it ...
  • Hi,
    I have one more doubt also.
    When I m using " _log()",where should i lookfor the log file .
    Means inside sahi folder where the logfile is getting generated?
  • Hi,
    Did anybody get some solution regardig this?
  • Hi,

    _log() generates the log line inside your html log file that you view by clicking "View Logs" link on the sahi controller.
    You can also find the log in /sahi/logs folder.

    Regards,
    Pankaj.
  • narayannarayan Administrators
    Here's the solution (for _logException)

    https://sourceforge.net/project/showfiles.php?group_id=151639&package_id=309861&release_id=667852

    This build is a nightly build, but you can use it. All changes will be incorporated in the new stable build, which should come soon enough.

    Regards,
    Narayan
  • thank u Narayan.
  • Thanks Narayan for the post.... :)
  • Hi Narayan,

    Can I redirect exceptions which Im getting on the command prompt runing SAHI.bat on to alertbox. Presently, I can use only custom messages.

    Regards,
    Ashvin.
Sign In or Register to comment.