If you were designing a standard library of a high level language (like Rust, C++, etc.) what would it do if while getting the current time of day (e.g. SystemTime::now()) it encountered a failed kernel system call (e.g. to clock_gettime) and why?

What do you think the existing implementations do?

  • Return error or raise exception
  • Return 0
  • Return undefined values (like stack garbage)
  • Panic/crash/segfault
you are viewing a single comment's thread
view the rest of the comments
[–] 7 points 1 year ago* (4 children)

you should do what's idiomatic for that language, e.g.: return an error in Rust; raise an exception in Python or Java; return an integer != 0 in C; etc.

Panic/crash/segfault

probably the worst option for a library

  • source
  • hideshow 4 child comments
  • [–] [S] 2 points 1 year ago (2 children)

    probably the worst option for a library

    Even worse than returning garbage? :)

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 year ago* (last edited 1 year ago) (1 child)

    If it's garbage as in a string with a bunch of information that is hard to parse, yeah, crashing without giving the caller a way to avoid it might be worse. But what is exactly this garbage and in what cases are you considering returning it at all?

  • source
  • parent
  • hideshow 1 child comment