2015-06-28 63 views
0

我有這樣的代碼:如何在nodeJS中捕獲錯誤?

try { 
    var client = new Steam.SteamClient(); 

    client.logOn(credentials); 
} catch(err) { 
    console.log(err); 
    return; 
} 

但仍然無法捕獲的錯誤:

MacBook-Pro:steam $ node test.js 
\events.js:85 
     throw er; // Unhandled 'error' event 
      ^
Error: Logon fail: 63 
    at SteamClient.handlers.(anonymous function) (/Users/Sites/steam/node_modules/steam/lib/handlers/user.js:178:11) 
    at SteamClient._netMsgReceived (/Users/Sites/steam/node_modules/steam/lib/steam_client.js:106:26) 
    at SteamClient.handlers.(anonymous function) (/Users/Sites/steam/node_modules/steam/lib/steam_client.js:192:10) 
    at SteamClient._netMsgReceived (/Users/Sites/steam/node_modules/steam/lib/steam_client.js:106:26) 
    at Connection.emit (events.js:107:17) 
    at Connection._readPacket (/Users/Sites/steam/node_modules/steam/lib/connection.js:50:8) 
    at Connection.emit (events.js:104:17) 
    at emitReadable_ (_stream_readable.js:424:10) 
    at emitReadable (_stream_readable.js:418:7) 
    at readableAddChunk (_stream_readable.js:174:11) 

的問題是,我有ACC的列表,只需要那些權威性,這是好的。但在這個錯誤程序關閉。

回答

2

錯誤通過Steam客戶端的事件傳遞,而不是通過例外。

試試這個:

var client = new Steam.SteamClient(); 

client.logOn(credentials); 
client.on('error', function(err) { 
    console.error('An error happened!'); 
    console.error(err); 
}); 

更多here