{"id":18326511,"url":"https://github.com/ghosind/go-try","last_synced_at":"2025-04-09T16:25:28.049Z","repository":{"id":232050458,"uuid":"781490682","full_name":"ghosind/go-try","owner":"ghosind","description":"The try...catch...finally statement alternative in Golang.","archived":false,"fork":false,"pushed_at":"2024-04-12T13:19:17.000Z","size":17,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T09:46:04.280Z","etag":null,"topics":["go-library","go-package","go-try-catch","try-catch","try-catch-wrap"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ghosind/go-try","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghosind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-03T13:37:14.000Z","updated_at":"2024-04-12T10:16:25.000Z","dependencies_parsed_at":"2024-04-07T17:29:59.872Z","dependency_job_id":"c045e93e-2077-4ac9-93ae-b11a1852e6d7","html_url":"https://github.com/ghosind/go-try","commit_stats":null,"previous_names":["ghosind/go-try"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Fgo-try","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Fgo-try/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Fgo-try/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Fgo-try/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghosind","download_url":"https://codeload.github.com/ghosind/go-try/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248066335,"owners_count":21042087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go-library","go-package","go-try-catch","try-catch","try-catch-wrap"],"created_at":"2024-11-05T19:07:07.087Z","updated_at":"2025-04-09T16:25:28.017Z","avatar_url":"https://github.com/ghosind.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-try\n\n![test](https://github.com/ghosind/go-try/workflows/test/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ghosind/go-try)](https://goreportcard.com/report/github.com/ghosind/go-try)\n[![codecov](https://codecov.io/gh/ghosind/go-try/branch/main/graph/badge.svg)](https://codecov.io/gh/ghosind/go-try)\n![Version Badge](https://img.shields.io/github/v/release/ghosind/go-try)\n![License Badge](https://img.shields.io/github/license/ghosind/go-try)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ghosind/go-try.svg)](https://pkg.go.dev/github.com/ghosind/go-try)\n\nThe `try...catch` statement alternative in Golang.\n\n## Installation\n\n```\ngo get -u github.com/ghosind/go-try\n```\n\n## Getting Started\n\nThere is the simplest example to run a function and handle the error in the `catch` function that the `try` function returned.\n\n```go\nout, err := try.TryCatch(func () (error) {\n  // Do something\n  return err\n}, func (err error) {\n  // The function will not executing if err is nil.\n  // Handle error...\n})\n```\n\nThe try functions will return two values. The first value is the all values the `try` function returned, and the second value is the error that the `try` function returns or it panics.\n\n```go\nout, err := try.Try(func () (string, error) {\n  return \"Hello world\", errors.New(\"expected error\")\n})\nfmt.Println(out)\nfmt.Println(err)\n// [Hello world, expected error]\n// expected error\n```\n\nThe package provides four forms for the `try` statement alternative:\n\n- `Try`\n- `TryFinally`\n- `TryCatch`\n- `TryCatchFinally`\n\nIn default cases, the try functions will catch the error that the `try` function panics, and you can set the `CatchPanic` variable to `false` to disable it.\n\n```go\ntry.CatchPanic = false\ntry.Try(func () {\n  panic(\"panic error\")\n})\n// panic: expected error\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosind%2Fgo-try","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghosind%2Fgo-try","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosind%2Fgo-try/lists"}