I have an IFrame in a page and IFrame has some JavaScript. At run time JavaScript in IFrame gives exception which i want to catch on parent window. How to do that?
        
There may be few possible causes for .onError() function not to work it may be because of cross domain URL's for this you should implement a check before actulally laoding the iFrame and for that use 
var url = "google.com"
var loading_url = "/empty.html"
document.getElementById("iframe").src = loading_url;
$.ajax({
url: url,
type: 'GET',
complete: function(e, xhr, settings){
     if(e.status === 200){
          document.getElementById("iframe").src = url;
     }
  }
});
This will not work cross domain, the status code is 0 in those cases.
One more thing to check is .onError() handler please check from below sample if it matches your conditions
How can I handle errors in loading an iframe?
There are many other options or tweaks to handle this kind of errors :
if (frameDoc.title == 'title of page after expection occur')
will also do the work using on .onLoad() event of iFrame.