Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can std::chrono::system_clock::now() throw an exception?

I want to write a very portable code, and I need to call std::chrono::system_clock::now() in the initialization. Can this function throw an exception ?

In c++11 standard, there is no mention of that issue. (At least, I didn't found one)

In Visual Studio, the sourcecode is as follow :

static time_point now() _NOEXCEPT
    {   // get current time
    return (time_point(duration(_Xtime_get_ticks())));
    }

With the _NOEXCEPT keyword, the answer in visual studio is pretty obvious. But what about the general case ?

like image 929
Arnaud Avatar asked Nov 23 '25 06:11

Arnaud


1 Answers

From §20.11.7.1

class system_clock {
public:
  ...
    static time_point now() noexcept;  
  ...
};

So the standard states it cannot throw an exception.

like image 153
Praetorian Avatar answered Nov 25 '25 18:11

Praetorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!