simpleyuji Posted June 27, 2017 Share Posted June 27, 2017 Im making a multiplayer game using phaser on client and node.js/socket.io on server and I'm currently not sure how to handle exceptions on server-side. Basically, whenever there are uncaught exceptions (perhaps due to some edgecase i didnt foresee), the server will crash, and the game state which gets stored in-memory for speed and updated every 33ms will get lost, including disconnecting all connected players (ie. 20 players will get disconnected if there's an unexpected server bug). Even if there's automatic restart, it'll be a new process with new memory and new socket connections. So my question is, how do i auto-catch these exceptions, so that I can handle them via an email notifier instead, and let the game continue on smoothly (prevent client disconnect) ? Link to comment Share on other sites More sharing options...
Skeptron Posted June 28, 2017 Share Posted June 28, 2017 I think that you should really put much effort in not having those exceptions in the first place. I know it sounds easy and dumb, but there's no real reason why you should be ok with having exceptions. Try to find repro-steps and fix the bug. Even if you managed to properly catch the exception, it might still have bad consequences on the game and thus on the players experience. If you really don't mind having those errors, I don't see any magical solution. Try to put a try{}catch{} at the very root of your code (probably where the Phaser game is instantiated or something like that), and log/mail the exception instead of throwing it. Link to comment Share on other sites More sharing options...
simpleyuji Posted July 8, 2017 Author Share Posted July 8, 2017 Thanks for the reply. Just saw this. I ended up, just having a baseSocketHandler for all events, and doing a try{} catch {} on any exceptions that bubble up. Link to comment Share on other sites More sharing options...
Recommended Posts