Understanding try..catch in Javascript

Posted by user295189 on Stack Overflow See other posts from Stack Overflow or by user295189
Published on 2010-04-15T16:32:49Z Indexed on 2010/04/15 17:03 UTC
Read the original article Hit count: 489

I have this try and catch problem. I am trying to redirect to a different page. But sometimes it does and some times it doesnt. I think the problem is in try and catch . can someone help me understand this. Thanks

var pg = new Object();
var da = document.all;
var wo = window.opener;

pg.changeHideReasonID = function(){
 if(pg.hideReasonID.value == 0 && pg.hideReasonID.selectedIndex > 0){
  pg.otherReason.style.backgroundColor = "ffffff";
  pg.otherReason.disabled = 0;
  pg.otherReason.focus();
 } else {
  pg.otherReason.style.backgroundColor = "f5f5f5";
  pg.otherReason.disabled = 1;
 }
}

pg.exit = function(pid){

 try {
  if(window.opener.hideRecordReload){
   window.opener.hideRecordReload(pg.recordID, pg.recordTypeID);

  } else {
   window.opener.pg.hideRecord(pg.recordID, pg.recordTypeID);

  }
 } catch(e) {}
 try {
  window.opener.pg.hideEncounter(pg.recordID);

 } catch(e) {}
 try {
  window.opener.pg.hideRecordResponse(pg.hideReasonID.value == 0 ? pg.otherReason.value : pg.hideReasonID.options[pg.hideReasonID.selectedIndex].text);

 } catch(e) {}
 try {
  window.opener.pg.hideRecord_Response(pg.recordID, pg.recordTypeID);

 } catch(e) {}
 try {
  window.opener.pg.hideRecord_Response(pg.recordID, pg.recordTypeID);

 } catch(e) {}
 try {
  window.opener.window.parent.frames[1].pg.loadQualityMeasureRequest();

 } catch(e) {}
 try {
  window.opener.pg.closeWindow();

 } catch(e) {} 



   parent.loadCenter2({reportName:'redirectedpage',patientID:pid});          
 parent.$.fancybox.close();

}

pg.hideRecord = function(){
      var pid = this.pid;

 pg.otherReason.value = pg.otherReason.value.trim();
 if(pg.hideReasonID.selectedIndex == 0){
  alert("You have not indicated your reason for hiding this record.");
  pg.hideReasonID.focus();
 } else if(pg.hideReasonID.value == 0 && pg.hideReasonID.selectedIndex > 0 && pg.otherReason.value.length < 2){
  alert("You have indicated that you wish to enter a reason\nnot on the list, but you have not entered a reason.");
  pg.otherReason.focus();
 } else {
  pg.workin(1);
  var n = new Object();
  n.noheaders = 1;
  n.recordID = pg.recordID;
  n.recordType = pg.recordType;
  n.recordTypeID = pg.recordTypeID;
  n.encounterID = request.encounterID;
  n.hideReasonID = pg.hideReasonID.value;
  n.hideReason = pg.hideReasonID.value == 0 ? pg.otherReason.value : pg.hideReasonID.options[pg.hideReasonID.selectedIndex].text;

  Connect.Ajax.Post("/emr/hideRecord/act_hideRecord.php", n, pg.exit(pid));


 }
}

pg.init = function(){
 pg.blocker = da.blocker;
 pg.hourglass = da.hourglass;

 pg.content = da.pageContent;

 pg.recordType = da.recordType.value;
 pg.recordID = parseInt(da.recordID.value);
 pg.recordTypeID = parseInt(da.recordTypeID.value);

 pg.information = da.information;

 pg.hideReasonID = da.hideReasonID;
 pg.hideReasonID.onchange = pg.changeHideReasonID;
 pg.hideReasonID.tabIndex = 1;

 pg.otherReason = da.otherReason;
 pg.otherReason.tabIndex = 2;
 pg.otherReason.onblur = function(){
  this.value = this.value.trim();
 }
 pg.otherReason.onfocus = function(){
  this.select();
 }

 pg.btnCancel = da.btnCancel;
 pg.btnCancel.tabIndex = 4;
 pg.btnCancel.title = "Close this window";
 pg.btnCancel.onclick = function(){
  //window.close();
  parent.$.fancybox.close(); 
 }

 pg.btnHide = da.btnHide;
 pg.btnHide.tabIndex = 3;
 pg.btnHide.onclick = pg.hideRecord;
 pg.btnHide.title = "Hide " + pg.recordType.toLowerCase() + " record";

 document.body.onselectstart = function(){
  if(event.srcElement.tagName.search(/INPUT|TEXT/i)){
   return false;
  }
 }

 pg.workin(0);
}

pg.workin = function(){
 var n = arguments.length ? arguments[0] : 1;
 pg.content.disabled = pg.hideReasonID.disabled = n;
 pg.blocker.style.display = pg.hourglass.style.display = n ? "block" : "none";
 if(n){
  pg.otherReason.disabled = 1;
  pg.otherReason.style.backgroundColor = "f5f5f5";
 } else {
  pg.otherReason.disabled = !(pg.hideReasonID.value == 0 && pg.hideReasonID.selectedIndex > 0);
  pg.otherReason.style.backgroundColor = pg.otherReason.disabled ? "f5f5f5" : "ffffff";
  pg.hideReasonID.focus();
 }
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about exception-handling