help
help copied to clipboard
Question: Does node raise exceptions on 'setTimeout' etc.?
Node uses libuv. In libuv functions like starting a timer can return an error code. In the documentation of node I cannot find any hint that a call to setTimeout can raise an exception. How is this possible? Or does setTimeout raise an exception if the corresponding libuv function returns an error code and it is just not documented?
Thanks for any clarification.
Regards Helmut
@hbr - is this outstanding? where did you find libuv timer functions as returning error codes? I checked http://docs.libuv.org/en/v1.x/timer.html and did not find one.
@gireeshpunathil: the functions uv_timer_init and uv_timer_start return an int. The general description says that negative numbers are error codes. If there were no error possibilities, then the functions should return void which other functions that cannot fail do (e.g. uv_timer_set_repeat).
@hbr - thanks for clarification. looking at the sources here https://github.com/libuv/libuv/blob/47e0c5c575e92a25e0da10fc25b2732942c929f3/src/timer.c#L58-L64
and here
https://github.com/libuv/libuv/blob/5c85d67bc781430f2db8f446795494aa8d399de8/src/uv-common.h#L306-L314
I don't see any error scenarios - either explicitly or implicitly. Am I missing anything? In either case, let me ping @nodejs/libuv for an opinion.
Thank you that you looked up the sources. I don't see any return of error codes either. But then the question is: Why did the designers not choose void as a return value?
I have pinged libuv team; let us hope to get an answer from them.
cc @nodejs/libuv
Why did the designers not choose
voidas a return value?
Likely to guarantee backward compatibility in case the function does ever return an error code. Some future implementation might require a dynamic memory allocation that might fail or so.
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.