# \`warns\` as a non-returning \`throws\`

**URL:** <https://forums.swift.org/t/warns-as-a-non-returning-throws/88533>\
**Category:** Discussion\
**Created:** [July 25, 2026, 4:54am UTC](https://forums.swift.org/t/warns-as-a-non-returning-throws/88533 "2026-07-25T04:54:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![No\_Pen\_3825](https://avatars.discourse-cdn.com/v4/letter/n/48db29/32.png) [@No\_Pen\_3825](https://forums.swift.org/u/No_Pen_3825)\
**Post date:** [July 25, 2026, 4:54am UTC](https://forums.swift.org/t/warns-as-a-non-returning-throws/88533/1 "2026-07-25T04:54:47Z")

</div>

Sometimes, even when I can recover and continue, I'd like to bubble some message back up about what the hiccup was and how I fixed it. One solution for this would be a new `warns` keyword which works much like `throws`, except it doesn't return. Take `func parse(_ source: String) throws -> AST`, for example, which would parse the given Swift up to an Abstract Syntax Tree. Let's say it runs into a small issue, an implicit cast to `Any`, let's say. Our parser is smart enough to fix the issue on its own, but we really should tell someone, preferably without throwing from the whole parser.

This could be done natively like so:

- `func parse(_ source: String) throws -> (ast: AST, warnings: [Warning])`
- `func parse(_ source: String, _ warn: (Warning) throws -> Void) throws -> AST`
- `func parse(_ source: String, _ warningsCont: AsyncStream<Warning>.Continuation) throws -> AST`

Or with `warns` like so:

- `func parse(_ source: String) throws warns -> AST`

To handle warns, you'd use `do-warning`:

```swift
do {
  try parse(#"print(Optional("hello world"))"#)
} warning {
  // handle warning
}

```

That being said, I don't think warns is a good idea, really. I think any of the other native methods are arguably already better, and more importantly already here and well supported. Just a thought.
