Questions tagged [exception-safety]
93 questions
1
vote
0 answers
std::tuple is not exception safe, and neither are regular structs
I am messing around with throwing move constructors and assignment operators.
It is a well known problem with std::vector that the vector elements have to be copied on reallocation, and cannot be moved, if the move constructor of said elements is…

super
- 278
- 1
- 11
1
vote
0 answers
What is the correct way of handling exceptions in Kotlin?
In Java, Android Studio gives Unhandled Exception error for some functions. for e.g., when we write code for converting a String to a Date variable, it shows Unhandled Exception:ParseException & pressing Alt+Insert automatically adds the try catch…

jaroos
- 41
- 3
1
vote
0 answers
What can (and should) I do if Drop panics? Can I free other resources anyway?
I've got a simple resource which uses MaybeUninit and unsafe for external reasons:
pub struct Resource<'a, T> {
repr: std::cell::RefMut<'a, std::mem::MaybeUninit>
}
impl<'a, T> Drop for Resource<'a, T> {
fn drop(&mut self) {
…

passing_through
- 1,778
- 12
- 24
1
vote
1 answer
How is std::atomic::operator= implemented for immutable types?
I've learned that one way to communicate between threads is to share some atomic data structure. For example:
struct Point {
int const x, y;
};
std::atomic some_point_in_shared_memory{Point{0, 0}};
Despite Point::operator=(Point const…

Benny K
- 868
- 6
- 18
1
vote
1 answer
Exception guarantees when moving object into std::vector
If memory allocation fails while moving a object into a std::vector, and bad_alloc is thrown, does std::vector guarantee that the moved from object is unaltered/still valid ?
For example:
std::string str = "Hello, World!";
std::vector…

Unimportant
- 2,076
- 14
- 19
1
vote
2 answers
Why do destructors run when a panic occurs?
If a Rust program panics, and assuming there are no panic catchers (which for a while there wasn't), surely it would be safe and fine to not run destructors and just let the OS clean up after the process. Why does Rust unwind the thread?
The only…

Timidger
- 1,199
- 11
- 15
1
vote
3 answers
Can declaring POD types throw an exception?
When I declare a condition_variable, it may throw std::system_error.
But how about when I declare a POD type (e.g. int, double or float)?
Like the code below:
int main()
{
//do something
int i; //will here throw exception?
}
If declaring…

Caesar
- 971
- 6
- 13
1
vote
3 answers
Do C standard library functions which are included in C++ throw exception?
In the below code, author points that new operator function call might cause an exception so that this implementation is not exception safe because object state is already changed in the first line.
String &String::operator =( const char *str ) {
…

Validus Oculus
- 2,756
- 1
- 25
- 34
1
vote
1 answer
DirectX 11 API and exception safety
Is there anywhere I can find documentation on the exception safety levels of different methods in the DirectX 11 API?

Mark
- 155
- 3
- 16
1
vote
0 answers
Creation of a strong reference to COM object in ROT with C#
I need to bind to a running COM instance (there can be many instances of what I am looking for, so I need to figure out which one is the right one by examinating the Running Object Table) Using CoClassCreate or the new operator with the class is no…

jdehaan
- 19,700
- 6
- 57
- 97
0
votes
1 answer
Exception-safe logging in java
I have a (probably) weird question about logging in an exception-safe way in java.
Let's say I have this code in java:
if (log.isDebugEnabled())
{
log.debug(...expression...);
}
Is there a best practice for logging ...expression.. in a way that…

Rossomoto
- 9
- 1
0
votes
1 answer
Does std::string class handle clean up if the assignment operator fails due to length_error or bad_alloc?
Does std::string class handle clean up if the assignment operator fails due to length_error or bad_alloc? Does it give me back my intact string I provided?
UPDATE:
SOLVED: YES OPERATOR= IS SAFE PER MY REQUIREMENTS. THE CODE BELOW ADDS NO VALUE TO…

FredFrugal
- 75
- 1
- 10
0
votes
2 answers
Throw when reassigning
try
{
object = mayThrow();
}
catch (const std::exception& exc)
{
//...
}
If mayThrow() actually throws, will the original object be untouched? Or is it better to do it this way?
try
{
Object newObject = mayThrow();
object =…

Alexey104
- 969
- 1
- 5
- 17
0
votes
1 answer
Combining ResourceT with bracket in a streaming pipeline
Here a simplification of my code:
import Database.PostgreSQL.Simple (Connection)
import qualified Streaming.Prelude as S
import Streaming.ByteString.Char8 as C
import Streaming.Zip (gunzip)
import Streaming
main :: IO ()
main = do
res <-…

xbalaj
- 977
- 1
- 8
- 14
0
votes
2 answers
safety -- late initialization error // FLUTTER
I have an error in the code because of safety in Flutter and I have tried to solve it with the declaration of variables using LATE.