Skip to content

Commit 9ebc0bd

Browse files
[SwiftToCxx] Trowing Swift::Error instead of NaiveException
1 parent ec10c5f commit 9ebc0bd

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
695695
// Create the condition and the statement to throw an exception.
696696
if (hasThrows) {
697697
os << " if (opaqueError != nullptr)\n";
698-
os << " throw (swift::_impl::NaiveException(\"Exception\"));\n";
698+
os << " throw (swift::_impl::swift::Error(opaqueError));\n";
699699
}
700700

701701
// Return the function result value if it doesn't throw.

stdlib/public/SwiftShims/_SwiftCxxInteroperability.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ namespace swift {
180180
class Error {
181181
public:
182182
Error() {}
183+
Error(void* _Nonnull swiftError) { opaqueValue = swiftError; }
183184
~Error() {
184185
if (opaqueValue)
185186
swift_errorRelease(opaqueValue);

test/Interop/SwiftToCxx/functions/swift-functions-errors-execution.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ int main() {
2121

2222
try {
2323
Functions::emptyThrowFunction();
24-
} catch (swift::_impl::NaiveException& e) {
25-
printf("%s\n", e.getMessage());
24+
} catch (swift::_impl::swift::Error& e) {
25+
printf("Exception\n");
2626
}
2727
try {
2828
Functions::throwFunction();
29-
} catch (swift::_impl::NaiveException& e) {
30-
printf("%s\n", e.getMessage());
29+
} catch (swift::_impl::swift::Error& e) {
30+
printf("Exception\n");
3131
}
3232
try {
3333
Functions::throwFunctionWithReturn();
34-
} catch (swift::_impl::NaiveException& e) {
35-
printf("%s\n", e.getMessage());
34+
} catch (swift::_impl::swift::Error& e) {
35+
printf("Exception\n");
3636
}
3737

3838
return 0;

test/Interop/SwiftToCxx/functions/swift-functions-errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }
2525
// CHECK: void* self = nullptr;
2626
// CHECK: _impl::$s9Functions18emptyThrowFunctionyyKF(self, &opaqueError);
2727
// CHECK: if (opaqueError != nullptr)
28-
// CHECK: throw (swift::_impl::NaiveException("Exception"));
28+
// CHECK: throw (swift::_impl::swift::Error(opaqueError))
2929
// CHECK: }
3030

3131
public func throwFunction() throws {
@@ -38,7 +38,7 @@ public func throwFunction() throws {
3838
// CHECK: void* self = nullptr;
3939
// CHECK: _impl::$s9Functions13throwFunctionyyKF(self, &opaqueError);
4040
// CHECK: if (opaqueError != nullptr)
41-
// CHECK: throw (swift::_impl::NaiveException("Exception"));
41+
// CHECK: throw (swift::_impl::swift::Error(opaqueError))
4242
// CHECK: }
4343

4444
public func throwFunctionWithReturn() throws -> Int {
@@ -52,6 +52,6 @@ public func throwFunctionWithReturn() throws -> Int {
5252
// CHECK: void* self = nullptr;
5353
// CHECK: auto returnValue = _impl::$s9Functions23throwFunctionWithReturnSiyKF(self, &opaqueError);
5454
// CHECK: if (opaqueError != nullptr)
55-
// CHECK: throw (swift::_impl::NaiveException("Exception"));
55+
// CHECK: throw (swift::_impl::swift::Error(opaqueError))
5656
// CHECK: return returnValue;
5757
// CHECK: }

0 commit comments

Comments
 (0)