Thelvyn
Thelvyn

Reputation: 264

std::thread without exceptions?

I wanted to know if there is a way to use std::thread without exceptions, if not what alternatives can I use ?

Actually I target windows and linux desktops but this may be extended in future.

edit: just using compiler options to disable exceptions, is not an acceptable solution. Errors have to be handed in one way or another.

The problem is that only exceptions that are used in my code are those handling std::thread errors. I'd like to get rid of those to have an exception-free code

edit2: I found tinythread++ library, it seems easy to modify if needed and works without exceptions.

Upvotes: 2

Views: 1326

Answers (1)

Luke B.
Luke B.

Reputation: 1288

You can disable STL's exceptions, but it's different for each compiler. Of course, since the standard actually says some exceptions must be thrown, whenever you do something that would throw an exception, you will get undefined behavior.

In gcc you disable exceptions by using -fno-exceptions

in MSVC: Can I disable exceptions in STL?

Upvotes: 1

Related Questions