Questions tagged [exception-safety]

93 questions
0
votes
2 answers

Exception Safety example guarantee correct?

I discuss the Exception Safety Guaratees and devised an example that I think provides the Strong Guarantee: template void strongSort(vector &data, LT lt) // works on pointers { vector temp { data }; // bad_alloc?…
towi
  • 21,587
  • 28
  • 106
  • 187
0
votes
1 answer

Where is it prohibited for target object of std::function to throw on destruction?

Consider std::function definition: namespace std { template class function; // not defined template class function { public: /* ... */ template function(F&&); /*…
Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79
0
votes
1 answer

Exception safety in the composite pattern

I used the composite pattern to represent devices, which I would like to shut down before killing their power (calling their dtor). I ran into a problem trying to group the devices, especially regarding their state. How would I proceed in the…
Guy
  • 23
  • 4
0
votes
1 answer

Why kotlin provide null safety operator but not exception safety operator?

If kotlin promotes safe code such as: val currentName = "Some Guy" getDataFromServer()?.getUsers()?.find { it.name == currentName }?.profilePicture?.let { showPicture(it) } ?: let { showAddPictureButton() } Why there is no similar syntax for…
xinaiz
  • 7,744
  • 6
  • 34
  • 78
0
votes
1 answer

Is it worth making my code less readable for providing exception safety in case of out of memory errors?

I have a game with non-copyable Items as they are supposed to be unique: class Item { Item() noexcept; Item(Item&&) noexcept; Item(Item const&) = delete; // ... }; class Creature is capable of receiving an Item and adding it to their…
0
votes
1 answer

Exception safe of containers in c++

I came across this term exception safe of containers. I want to understand what exactly exception safe mean? Are there are any comparison for this for different containers ?
Barry
  • 133
  • 1
  • 1
  • 9
0
votes
1 answer

std::terminate and destructors of empty containers

Consider some standard container which uses dynamic memory (i.e. is an AllocatorAwareContainer) and has a size and capacity of zero. For example, take a std::vector and call vec.resize(0); vec.shrink_to_fit();. I would imagine that such container…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
0
votes
1 answer

Cleanly and optionally redirect stderr or stdout to file

I have a Python3 script and I want to optionally redirect stdout and stderr to a file. Something like this: # variable declarations if log_output: output_file = open('output.txt', 'w') sys.stdout = output_file if log_errors: errors_file…
Ben
  • 5,952
  • 4
  • 33
  • 44
0
votes
2 answers

C++ : other one simple scope guard

Lets ask you about this simple scope guard: template struct finop_t { T& t; ~finop_t() { t(); } }; #define FINALLY__(l, cl) \ auto FIN ## l ## clo = cl; \ finop_t FIN ## l ## fin { FIN ## l ##…
funny_falcon
  • 427
  • 3
  • 11
0
votes
0 answers

Trying to get my head around a couple of things: RAII and exception safety

Ok, so I think I understand RAII. I think I have an idea what exception safety is about too. In order to conform to RAII, and in an attempt to make my code more exception safe, I have attempted to remove a margin for error from my cMain class.…
Mark
  • 155
  • 3
  • 16
0
votes
1 answer

Exception safety:

I would like to ask for some advice with regard to exception safety. In particular I have been referencing Do you (really) write exception safe code?. If I have a container of pointers to objects of type Node, and I were to clear and reinitialise…
user2406944
0
votes
2 answers

no-throw exception guarantee and stack overflow

There are several special functions which usually guarantee not to throw excpetions, e.g.: Destructors swap method Consider the following swap implementation, as stated in this answer: friend void swap(dumb_array& first, dumb_array& second) { …
Mikhail
  • 20,685
  • 7
  • 70
  • 146
0
votes
1 answer

Lua, threads and C++ exceptions

I'm planning on suggesting to my development team that we start looking at lua instead of C++ for the project we're currently working on. On that subject I have a question that I need to clear up first. With the current SDK, we are not allowed to…
Robin Heggelund Hansen
  • 4,906
  • 6
  • 37
  • 54
0
votes
1 answer

Is uninitialized_copy() exception-safe?

MSDN and other places say that uninitialized_copy provides a strong exception guarantee, but other C++ references don't. Is this in fact guaranteed by C++, or not?
user541686
  • 205,094
  • 128
  • 528
  • 886
-1
votes
2 answers

Which exception safety guarantee do we have when copying a C++ container?

When any allocation of the new container or copying of the elements fails with an exception, will the current contents of the target container remain intact?