TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Golang :how do i handle index out of range error?

1 pointsby pvsukale1about 9 years ago
I am writing a CLI interface program in Go.my program requires a user to enter a filename as an argument . following is the code I wrote to handle the situations in which user doesn&#x27;t enter any argument . but it panics and gives an error &quot;index out of range&quot;.how do I handle this?<p>if len(os.Args) == 0 { fmt.Println(&quot;usage: gohex &lt;filename&gt;&quot;)<p><pre><code> os.Exit(1) }</code></pre>

no comments

no comments