Bosma / Scheduler

Modern C++ Scheduling Library
MIT License
273 stars 75 forks source link

Unsupported cron string leads to unhandled exception #9

Closed Tickwick closed 6 years ago

Tickwick commented 6 years ago

cronScheduler.cron("*/5 * * * *", []() { Foo(); });

This leads to an "invalid stoi argument" exception, at least on MSVC 15.6. I think it's the responsability of the library to gracefully handle incorrect or unsupported arguments for its functions.

Bosma commented 6 years ago

I didn't take into account that type of malformed cron string, thanks for reporting.

It continues to throw an exception, however it is a more descriptive BadCronExpression exception that contains a message with the error.

Tickwick commented 6 years ago

Any plans on supporting that type of cron string in the future?

Bosma commented 6 years ago

Sorry, I didn't realize that were more complicated expressions. I added in the latest commit an alternative cron function ccron that uses a different (included) library. This should work for you, let me know.

Tickwick commented 6 years ago

Thanks for the support, first a couple of minor issues:

  1. Wrong include path
  2. Here and on the catch below that, there's an unused declared e var that throws warnings on compile.

Second, as it stands now, due to the C lib include, this library is not header only anymore, any usage of ccron requires compilation of ccronexpr.c.

Bosma commented 6 years ago

Yes you're right, I reset the last commit and moved it to a branch. I'd prefer to keep it header-only. If you want the functionality offered use the ccronexpr branch. The include path was correct given the include_directories entry in the cmakelists. I dropped the e. Thanks.