Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Error Handler

Hi experts, How to handle error on js? base on the code below, I want the alert will continue in spite of an error. I'm getting error this because "myProlist" is not found in the Html. My point here is to run the function in-spite of the error. Thank you!  

function GoAlert()
 {
   document.getElementById("myProlist").style.display = "none";
   alert("Okey");    
}

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

function GoAlert()
 {
  try{
    document.getElementById("myProlist").style.display = "none";
    alert("Okey");
  } catch (ex) {
    alert("not ok!");
  }
}

Open in new window

SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@norie

ID: 42125757 is not correct syntax...

also, it always alert "Okey" even if try/catch syntax is ok...
Avatar of Norie
Norie

Huseyin

I realised the syntax was incorrect but was unable to edit as someone posted a comment straight after mine.:)
so,

write it on notepad
test with jsFiddle
then copy/paste and submit

:) this is what I do now ha ha...
Avatar of Whing Dela Cruz

ASKER

Thanks both of you guys, more power!
I'm on my phone - can't really test anything,  working from memory basically.:)