socket.io get disconnected after throw new Error(or any other error) in certain place of my script.
consider the following or look at http://pastebin.com/G2KKiveC:
becGlobal.contents = [{ID: 1, type:"aContent" /* ... */}];// contents
s =
{
oSocket : (typeof io !== 'undefined') ? io('xxxxxxx') : '',
oVars : {
"contents" : becGlobal.contents
},
oFns : {
init : function(){
s.oSocket.on('response', s.oFns.response);
s.oVars.contents.forEach(function(aContent){
aContent.instance = new s.oFns[aContent.type](aContent);
aContent.instance.c.oFns.init();
});
}
}
};
s.oFns = $.extend(true,
s.oFns,
$.fn.appContents(s),
$.fn.appResponses(s)
);
s.oFns.init();
(function($){
$.fn.appContents = function(s){
return {
aContent : function(content){
var that = this;
this.c = {
oFns : {
clear : function () {
that.c.oBinds.contentHolder.html('');
},
init : function(){
},
draw : function(data){
console.log(data);
throw new Error("error"); // -> this error disconnects socket.io/ if i put this error anywhere else it does
}
}
};
}
//.. a lot more contents
//..
};
};
})(jQuery);
resp = {
ID : 1,
fName : "draw"// or init,
};
(function($){
$.fn.appResponses = function(s){
return {
response : function(resp)
{
var fName, i, content;
for(i = 0; i < s.oVars.contents.length; i++){
content = s.oVars.contents[i];
if(content.ID == resp.ID)
{
fName = 'draw';
if(typeof resp.fName !== 'undefined' && resp.fName != '')
{
fName = resp.fName;
}
content.instance.c.oVars.inProgress = true;
content.instance.c.oFns[fName](resp);
break;
}
}
}
};
}
})(jQuery);
I am talking about line 47, in draw method throw new Error() happened - that error causes socket.io to disconnect however if i throw the error elsewhere in the script socket.io wont disconnect.
Whats even weirder the error in draw does not appear on console.log at all.
Thanks