File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -572,6 +572,36 @@ CPPTRACE_TRY {
572
572
}
573
573
```
574
574
575
+ > [!CAUTION]
576
+ > There is a footgun with `return ` statements in these try /catch macros: The implementation on Windows requires wrapping
577
+ > the try body in an immediately-invoked lambda and and as such `return ` statements return from the lambda not the
578
+ > enclosing function. If you' re writing code that will be compiled on windows, it' s important to not write `return `
579
+ > statements within CPPTRACE_TRY. E.g., this does not work as expected on windows:
580
+ > ```cpp
581
+ > CPPTRACE_TRY {
582
+ > if(condition) return 40; // does not return from the enclosing function on windows
583
+ > } CPPTRACE_CATCH(const std::exception& e) {
584
+ > ...
585
+ > }
586
+ > return 20;
587
+ > ```
588
+
589
+ > [!WARNING]
590
+ > There is one other footgun which is mainly relevant for code that was written on an older version of cpptrace: It's
591
+ > possible to write the following without getting errors
592
+ > ```cpp
593
+ > CPPTRACE_TRY {
594
+ > ...
595
+ > } CPPTRACE_CATCH(const std::runtime_error& e) {
596
+ > ...
597
+ > } catch(const std::exception& e) {
598
+ > ...
599
+ > }
600
+ > ```
601
+ > This code will compile and in some sense work as expected as the second catch handler will work, however, cpptrace
602
+ > won't know about the handler and as such it would be able to correctly collect a trace on a non-`std::runtime_error`
603
+ > that is thrown. No run-time errors will occur, however, `from_current_exception` may report a misleading trace.
604
+
575
605
### Removing the `CPPTRACE_` prefix
576
606
577
607
`CPPTRACE_TRY` is a little cumbersome to type. To remove the `CPPTRACE_` prefix you can use the
You can’t perform that action at this time.
0 commit comments