Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture the language exception #181

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions swiftwinrt/Resources/Support/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ public struct Error : Swift.Error, CustomStringConvertible {
}
}

public func failWith(err: HRESULT) -> HRESULT {
return err
public func failWith(hr: HRESULT) -> HRESULT {
return hr
}

public func failWith(error: Swift.Error) -> HRESULT {
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
var hresult: HRESULT = E_FAIL
let message = error.description
if let winrtError = error as? Error {
hresult = winrtError.hr
}

do {
try message.withHStringRef {
_ = RoOriginateLanguageException(hresult, $0, nil)
}
} catch {
_ = RoOriginateLanguageException(hresult, nil, nil)
}

return hresult
}
4 changes: 2 additions & 2 deletions swiftwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ override % func _getABI<T>() -> UnsafeMutablePointer<T>? {

static void write_not_implementable_vtable_method(writer& w, function_def const& sig)
{
w.write("%: { _, % in return failWith(err: E_NOTIMPL) }", get_abi_name(sig), bind([&](writer& w) {
w.write("%: { _, % in return failWith(hr: E_NOTIMPL) }", get_abi_name(sig), bind([&](writer& w) {
stevenbrix marked this conversation as resolved.
Show resolved Hide resolved
separator s{ w };
for (auto& param : sig.params)
{
Expand Down Expand Up @@ -2877,7 +2877,7 @@ override % func _getABI<T>() -> UnsafeMutablePointer<T>? {
w.write("return S_OK\n");
}
if (needs_try_catch) {
w.write("} catch { return failWith(err: E_FAIL) } \n");
w.write("} catch { return failWith(error: error) } \n");
w.m_indent -= 1;
}
w.write("}");
Expand Down
Loading