0

I've a restify server that get requests from a client with some parameters to run a long process.

so, after initializing some attributes and some checks, the service returns a json to the client (and start processing asynchronusly). then the client can monitor the process via log files on sockets.

The problem is any exception before

res.send(jsonObject)

can be caught by

process.on('uncaughtException'...

but any exception after sending the response can't be caught!!!

regardless that handling exceptions this way isn't the best way and tailing on sockets isn't so good

I want to be able to catch the later exceptions that may occur after sending response to the client!!

AMTourky
  • 1,190
  • 13
  • 25

1 Answers1

0

Perhaps you should take a look at this post regarding exception handling. When an error bubbles up to uncaughtException it puts the process in an unknown state. If you'd instead like to isolate these exceptions then consider using domains to wrap your logic safely.

Per NodeJs documentation: "Note that uncaughtException is a very crude mechanism for exception handling and may be removed in the future.

Don't use it, use domains instead. If you do use it, restart your application after every unhandled exception!

Do not use it as the node.js equivalent of On Error Resume Next. An unhandled exception means your application - and by extension node.js itself - is in an undefined state. Blindly resuming means anything could happen.

Think of resuming as pulling the power cord when you are upgrading your system. Nine out of ten times nothing happens - but the 10th time, your system is bust.

You have been warned."

Community
  • 1
  • 1
Yousef
  • 401
  • 2
  • 8
  • yes, I know it's not recommended to use it, but the problem here is general. what happens to the stack after calling res.send() ? so that exceptions can't be caught? – AMTourky Jun 23 '14 at 15:40