Skip to content

Commit 9ce2a01

Browse files
test: Add more CppExceptions to macOS sample (#5189)
Add throwing an CppException from a bg thread and throwing from a noexcept function.
1 parent 5e2b8b5 commit 9ce2a01

File tree

6 files changed

+66
-16
lines changed

6 files changed

+66
-16
lines changed

Samples/macOS-Swift/Shared/Base.lproj/Main.storyboard

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23727" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23504"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23727"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<scenes>
@@ -706,14 +706,14 @@
706706
<objects>
707707
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="macOS_Swift" customModuleProvider="target" sceneMemberID="viewController">
708708
<view key="view" id="m2S-Jp-Qdl">
709-
<rect key="frame" x="0.0" y="0.0" width="480" height="656"/>
709+
<rect key="frame" x="0.0" y="0.0" width="480" height="677"/>
710710
<autoresizingMask key="autoresizingMask"/>
711711
<subviews>
712712
<stackView distribution="fill" orientation="vertical" alignment="centerX" spacing="12" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fsa-9g-bf3">
713-
<rect key="frame" x="104" y="30" width="273" height="597"/>
713+
<rect key="frame" x="104" y="8" width="273" height="661"/>
714714
<subviews>
715715
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="nAm-U5-PON">
716-
<rect key="frame" x="68" y="570" width="136" height="32"/>
716+
<rect key="frame" x="68" y="634" width="136" height="32"/>
717717
<buttonCell key="cell" type="push" title="Add Breadcrumb" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="zk9-d6-mm1">
718718
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
719719
<font key="font" metaFont="system"/>
@@ -723,7 +723,7 @@
723723
</connections>
724724
</button>
725725
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="dzU-Gi-2VZ">
726-
<rect key="frame" x="66" y="538" width="141" height="32"/>
726+
<rect key="frame" x="66" y="602" width="141" height="32"/>
727727
<buttonCell key="cell" type="push" title="Capture Message" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="EQH-kc-eDD">
728728
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
729729
<font key="font" metaFont="system"/>
@@ -733,7 +733,7 @@
733733
</connections>
734734
</button>
735735
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LiD-mH-Y7l">
736-
<rect key="frame" x="78" y="506" width="116" height="32"/>
736+
<rect key="frame" x="78" y="570" width="116" height="32"/>
737737
<buttonCell key="cell" type="push" title="Capture Error" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Tlg-FD-XnA">
738738
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
739739
<font key="font" metaFont="system"/>
@@ -743,7 +743,7 @@
743743
</connections>
744744
</button>
745745
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zMq-8z-Bqi">
746-
<rect key="frame" x="63" y="474" width="146" height="32"/>
746+
<rect key="frame" x="63" y="538" width="146" height="32"/>
747747
<buttonCell key="cell" type="push" title="Capture Exception" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="PwR-RA-ikK">
748748
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
749749
<font key="font" metaFont="system"/>
@@ -753,7 +753,7 @@
753753
</connections>
754754
</button>
755755
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ocz-Nk-ZQ2">
756-
<rect key="frame" x="47" y="442" width="178" height="32"/>
756+
<rect key="frame" x="47" y="506" width="178" height="32"/>
757757
<buttonCell key="cell" type="push" title="Capture User Feedback" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="nui-gg-F5o">
758758
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
759759
<font key="font" metaFont="system"/>
@@ -763,7 +763,7 @@
763763
</connections>
764764
</button>
765765
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GQW-jy-1TZ">
766-
<rect key="frame" x="66" y="410" width="141" height="32"/>
766+
<rect key="frame" x="66" y="474" width="141" height="32"/>
767767
<buttonCell key="cell" type="push" title="raiseNSException" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="7rF-ep-EYR">
768768
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
769769
<font key="font" metaFont="system"/>
@@ -773,7 +773,7 @@
773773
</buttonCell>
774774
</button>
775775
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TkR-L2-cU3" userLabel="reportNSException">
776-
<rect key="frame" x="62" y="378" width="149" height="32"/>
776+
<rect key="frame" x="62" y="442" width="149" height="32"/>
777777
<buttonCell key="cell" type="push" title="reportNSException" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="89W-TG-dLd">
778778
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
779779
<font key="font" metaFont="system"/>
@@ -783,7 +783,7 @@
783783
</connections>
784784
</button>
785785
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HXP-Is-MDM">
786-
<rect key="frame" x="61" y="346" width="150" height="32"/>
786+
<rect key="frame" x="61" y="410" width="150" height="32"/>
787787
<buttonCell key="cell" type="push" title="NSRangeException" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="f0L-i6-NLd">
788788
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
789789
<font key="font" metaFont="system"/>
@@ -793,7 +793,7 @@
793793
</connections>
794794
</button>
795795
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="c5W-zA-19P">
796-
<rect key="frame" x="61" y="314" width="150" height="32"/>
796+
<rect key="frame" x="61" y="378" width="150" height="32"/>
797797
<buttonCell key="cell" type="push" title="captureTransaction" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="OVU-vi-LRM">
798798
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
799799
<font key="font" metaFont="system"/>
@@ -803,7 +803,7 @@
803803
</connections>
804804
</button>
805805
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0rS-ee-VAF">
806-
<rect key="frame" x="76" y="282" width="120" height="32"/>
806+
<rect key="frame" x="76" y="346" width="120" height="32"/>
807807
<buttonCell key="cell" type="push" title="Sentry.crash()" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="k1V-IH-Ru7">
808808
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
809809
<font key="font" metaFont="system"/>
@@ -813,7 +813,7 @@
813813
</connections>
814814
</button>
815815
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="sxu-g3-vT7" userLabel="CppException">
816-
<rect key="frame" x="75" y="250" width="123" height="32"/>
816+
<rect key="frame" x="75" y="314" width="123" height="32"/>
817817
<buttonCell key="cell" type="push" title="CPP Exception" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="B4S-qm-cMV">
818818
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
819819
<font key="font" metaFont="system"/>
@@ -823,7 +823,7 @@
823823
</connections>
824824
</button>
825825
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Cfu-21-l6L" userLabel="CppException">
826-
<rect key="frame" x="17" y="218" width="238" height="32"/>
826+
<rect key="frame" x="17" y="282" width="238" height="32"/>
827827
<buttonCell key="cell" type="push" title="Rethrow No Active CPP Exception" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="YRN-qy-qrz">
828828
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
829829
<font key="font" metaFont="system"/>
@@ -832,6 +832,26 @@
832832
</connections>
833833
</buttonCell>
834834
</button>
835+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JYd-F0-8fQ" userLabel="CppExceptionFromBGThread">
836+
<rect key="frame" x="25" y="250" width="223" height="32"/>
837+
<buttonCell key="cell" type="push" title="CPP Exception form BG Thread" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ewz-0Z-S9G" userLabel="CPP Exception from BG Thread">
838+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
839+
<font key="font" metaFont="system"/>
840+
<connections>
841+
<action selector="cppExceptionFromBGThread:" target="XfG-lQ-9wD" id="Nfn-44-SHp"/>
842+
</connections>
843+
</buttonCell>
844+
</button>
845+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="frA-ie-6al" userLabel="NoExceptCppException">
846+
<rect key="frame" x="44" y="218" width="185" height="32"/>
847+
<buttonCell key="cell" type="push" title="NoExcept CPP Exception" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hK0-9f-Amb">
848+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
849+
<font key="font" metaFont="system"/>
850+
</buttonCell>
851+
<connections>
852+
<action selector="noExceptCppException:" target="XfG-lQ-9wD" id="Iu4-2C-VH1"/>
853+
</connections>
854+
</button>
835855
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="onh-qf-HCq" userLabel="asyncCrash">
836856
<rect key="frame" x="83" y="186" width="107" height="32"/>
837857
<buttonCell key="cell" type="push" title="async crash" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3ec-oQ-wXv">
@@ -925,6 +945,8 @@
925945
<integer value="1000"/>
926946
<integer value="1000"/>
927947
<integer value="1000"/>
948+
<integer value="1000"/>
949+
<integer value="1000"/>
928950
</visibilityPriorities>
929951
<customSpacing>
930952
<real value="3.4028234663852886e+38"/>
@@ -946,6 +968,8 @@
946968
<real value="3.4028234663852886e+38"/>
947969
<real value="3.4028234663852886e+38"/>
948970
<real value="3.4028234663852886e+38"/>
971+
<real value="3.4028234663852886e+38"/>
972+
<real value="3.4028234663852886e+38"/>
949973
</customSpacing>
950974
</stackView>
951975
</subviews>

Samples/macOS-Swift/Shared/CppSample.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Sentry::CppSample::throwCPPException(void)
1313
internalFunction();
1414
}
1515

16+
void
17+
Sentry::CppSample::noExceptCppException() noexcept
18+
{
19+
throw std::invalid_argument("Invalid Argument.");
20+
}
21+
1622
void
1723
Sentry::CppSample::rethrowNoActiveCPPException(void)
1824
{

Samples/macOS-Swift/Shared/CppSample.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Sentry {
88
class CppSample {
99
public:
1010
void throwCPPException();
11+
void noExceptCppException() noexcept;
1112
void rethrowNoActiveCPPException();
1213
};
1314
}

Samples/macOS-Swift/Shared/CppWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@interface CppWrapper : NSObject
44
- (void)throwCPPException;
5+
- (void)noExceptCppException;
56
- (void)rethrowNoActiveCPPException;
67
- (void)throwNSRangeException;
78
@end

Samples/macOS-Swift/Shared/CppWrapper.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ - (void)throwCPPException
1010
cppTool.throwCPPException();
1111
}
1212

13+
- (void)noExceptCppException
14+
{
15+
Sentry::CppSample cppTool;
16+
cppTool.noExceptCppException();
17+
}
18+
1319
- (void)rethrowNoActiveCPPException
1420
{
1521
Sentry::CppSample cppTool;

Samples/macOS-Swift/Shared/ViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ class ViewController: NSViewController {
8787
wrapper.rethrowNoActiveCPPException()
8888
}
8989

90+
@IBAction func cppExceptionFromBGThread(_ sender: Any) {
91+
DispatchQueue.global().async {
92+
let wrapper = CppWrapper()
93+
wrapper.throwCPPException()
94+
}
95+
}
96+
97+
@IBAction func noExceptCppException(_ sender: Any) {
98+
let wrapper = CppWrapper()
99+
wrapper.noExceptCppException()
100+
}
101+
90102
@IBAction func asyncCrash(_ sender: Any) {
91103
DispatchQueue.main.async {
92104
self.asyncCrash1()

0 commit comments

Comments
 (0)