frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Proposal: Throw as a Special Variable for Auto Error Propagation in Go

2•iondodon•1d ago
Proposal: Implicit Error Propagation via `throw` Identifier in Go

Abstract

This proposal introduces a new syntactic convention to Go: the use of the identifier `throw` in variable declarations or assignments (e.g., `result, throw := errorFunc()`). When detected, the compiler will automatically insert a check for a non-nil error and return zero values for all non-error return values along with the error. This mechanism streamlines error handling without compromising Go's hallmark of explicit, readable code.

Motivation

Go encourages explicit error handling, which often results in repetitive boilerplate code. For example:

result, err := errorFunc() if err != nil { return zeroValue, err }

This pattern, while clear, adds verbosity that can hinder readability, especially in functions with multiple error-prone calls. By introducing a syntactic shorthand that preserves clarity, we can reduce boilerplate and improve developer ergonomics.

Proposal

When a variable named `throw` is assigned the result of a function returning an `error`, and the enclosing function returns an `error`, the compiler will implicitly insert:

if throw != nil { return zeroValues..., throw }

Applicable Scenarios

Short declarations:

  x, throw := doSomething()
Standard assignments:

  x, throw = doSomething()
Variable declarations with assignment:

  var x T; var throw error; x, throw = doSomething()


* `throw` must be a variable of type `error`

* The surrounding function must return an `error`

* The rule only applies when the variable is explicitly named `throw`

Example

Traditional Error Handling

func getUserData(id int) (data Data, err error) { data, err := fetch(id) if err != nil { return Data{}, err } return data, nil }

With `throw`

func getUserData(id int) (Data, error) {

    data, throw := fetch(id)
    // Automatically expands to: if throw != nil { return Data{}, throw }

    moreData, throw := fetchMore(id)
    // Automatically expands to: if throw != nil { return Data{}, throw }

    return data, nil
}

Comments

NoahZuniga•1d ago
While I have no experience with go, this seems like an interesting idea. Hackernews however isn't a great place to post this proposal if you want it to be implemented.

Maybe take a look at https://github.com/golang/proposal and if you want to share your proposal with hn, submit a link to the proposal here.

US Prosecutors Sought Builder.ai Data After Sales Overstated

https://www.bloomberg.com/news/articles/2025-05-26/us-prosecutors-sought-builder-ai-data-after-sales-overstated
1•perihelions•13s ago•0 comments

'Half the tree of life' ecologists' horror as nature reserves emptied of insects

https://www.theguardian.com/environment/2025/jun/03/climate-species-collapse-ecology-insects-nature-reserves-aoe
1•beardyw•2m ago•0 comments

How powerful is FLUX.1 Kontext?

https://fluxkontext.top
1•VidText_AI•5m ago•1 comments

The Future of Coding Is Here: An Inside Look at Amp

https://medium.com/@jonathanaraney_25643/the-future-of-coding-is-here-f1cbb2c3c77d
1•tosh•5m ago•0 comments

What the Trump Bullet Photo Taught Me about Modern Camera Shutters

https://substack.com/home/post/p-164991902
1•mwidell•7m ago•0 comments

Walmart is supercharging revenue – but with fewer workers

https://www.ft.com/content/5be70b28-018d-42d7-af8d-ea5a4bed4d44
1•aspenmayer•7m ago•1 comments

Why more than 50k passengers have booked on 'flights to nowhere'

https://www.standard.co.uk/news/london/british-airways-flights-to-nowhere-fear-of-flying-course-b1230891.html
1•iLoveOncall•8m ago•0 comments

Show HN: Gemma 3 1B fine-tuned for Arabic Grammatical Error Correction

https://huggingface.co/alnnahwi/gemma-3-1b-arabic-gec-v1
1•bahjat•8m ago•0 comments

Ubicloud: Open-Source Alternative to AWS

https://github.com/ubicloud/ubicloud
1•thunderbong•8m ago•0 comments

I built an AI Coach for managers who get zero training

https://learnmentalmodels.co/
1•sameedahmad•8m ago•0 comments

Miri Yudovich: "I'm just a very pragmatic person. I like to do things my way."

https://www.calcalistech.com/ctechnews/article/tttuhy74t
1•NoaEshed•9m ago•0 comments

Chinese battery glut plugs into solar boom to power Pakistan

https://www.ft.com/content/2b4c598e-a4b3-4c6e-9c38-97e46357f819
1•jahnu•9m ago•0 comments

Quarkdown: A modern Markdown-based typesetting system

https://github.com/iamgio/quarkdown
4•asicsp•10m ago•0 comments

Why monsoon rains wreak havoc annually in India's cities

https://www.bbc.com/news/articles/cr7zlm3mpejo
1•Brajeshwar•11m ago•0 comments

Not causal chains, but interactions and adaptations

https://surfingcomplexity.blog/2025/05/19/not-causal-chains-but-interactions-and-adaptations/
1•kiyanwang•11m ago•0 comments

Yoshua Bengio announces non-profit to develop 'honest' artificial intelligence

https://www.theguardian.com/technology/2025/jun/03/honest-ai-yoshua-bengio
1•billaboop•13m ago•0 comments

Example of Splitting a PR

https://www.jefftk.com/p/example-of-splitting-a-pr
2•todsacerdoti•13m ago•1 comments

DaisyUI – Tailwind CSS Components

https://daisyui.com/
2•tosh•14m ago•0 comments

Mount Etna eruption live: volcanic blast in Italy sends tourists fleeing

https://www.independent.co.uk/news/world/europe/mount-etna-eruption-volcano-smoke-lava-live-updates-b2761911.html
2•bravesoul2•16m ago•0 comments

SmolVLA: A Vision-Language-Action Model for Affordable and Efficient Robotics

https://arxiv.org/abs/2506.01844
2•AdilZtn•17m ago•0 comments

'AI' as Class Warfare

https://newintermag.com/ai-as-class-warfare/
3•pabs3•18m ago•0 comments

What's new for JFR in JDK 25

https://egahlin.github.io/2025/05/31/whats-new-in-jdk-25.html
2•Tomte•19m ago•0 comments

Bill Gates to give most of $200B fortune to Africa

https://www.bbc.com/news/articles/cn4qg5gzgzxo
6•0xedb•24m ago•1 comments

Ask HN: Bing Search API will be retired soon. What alternatives do you use?

1•druskacik•25m ago•0 comments

Ask HN: How do you struggle with/optimize for deep,sustained focus?

1•jenever•26m ago•0 comments

Uniqueness for Behavioural Types

https://kcsrk.info/ocaml/modes/2025/05/29/uniqueness_and_behavioural_types/
1•hwj•29m ago•0 comments

Versadok: Versatile document creation markup and library

https://github.com/gettalong/versadok
1•thunderbong•32m ago•0 comments

'It's thrilling': almost three centuries of the Belfast News Letter go online

https://www.theguardian.com/media/2025/jun/01/worlds-oldest-daily-belfast-news-letter-go-digital
2•thm•33m ago•0 comments

Information Density of Cuneiform Tablets (2016)

https://www.bookandsword.com/2016/10/29/the-information-density-of-cuneiform-tablets/
1•pastage•35m ago•0 comments

Unlicensed law clerk fired after ChatGPT hallucinations found in filing

https://arstechnica.com/tech-policy/2025/06/law-clerk-fired-over-chatgpt-use-after-firms-filing-used-ai-hallucinations/
3•01-_-•37m ago•0 comments