{"id":13485759,"url":"https://github.com/rainerhahnekamp/sneakythrow","last_synced_at":"2025-03-17T15:11:46.372Z","repository":{"id":44434152,"uuid":"122130001","full_name":"rainerhahnekamp/sneakythrow","owner":"rainerhahnekamp","description":"SneakyThrow is a Java library to ignore checked exceptions","archived":false,"fork":false,"pushed_at":"2019-10-24T10:34:02.000Z","size":2459,"stargazers_count":76,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-03T23:51:17.619Z","etag":null,"topics":["exception-handling","java"],"latest_commit_sha":null,"homepage":"","language":"Java","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/rainerhahnekamp.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}},"created_at":"2018-02-19T22:44:17.000Z","updated_at":"2025-01-26T20:13:53.000Z","dependencies_parsed_at":"2022-09-03T19:50:43.861Z","dependency_job_id":null,"html_url":"https://github.com/rainerhahnekamp/sneakythrow","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainerhahnekamp%2Fsneakythrow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainerhahnekamp%2Fsneakythrow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainerhahnekamp%2Fsneakythrow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainerhahnekamp%2Fsneakythrow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rainerhahnekamp","download_url":"https://codeload.github.com/rainerhahnekamp/sneakythrow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056425,"owners_count":20390719,"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":["exception-handling","java"],"created_at":"2024-07-31T18:00:31.221Z","updated_at":"2025-03-17T15:11:46.344Z","avatar_url":"https://github.com/rainerhahnekamp.png","language":"Java","funding_links":[],"categories":["Projects","项目"],"sub_categories":["Development","发展"],"readme":"# SneakyThrow\n\n[![Build Status](https://travis-ci.org/rainerhahnekamp/sneakythrow.svg?branch=master)](https://travis-ci.org/rainerhahnekamp/sneakythrow.svg?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/rainerhahnekamp/sneakythrow/badge.svg?branch=master)](https://coveralls.io/github/rainerhahnekamp/sneakythrow?branch=master)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.rainerhahnekamp/sneakythrow/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.rainerhahnekamp/sneakythrow)\n[![Javadocs](https://www.javadoc.io/badge/com.rainerhahnekamp/sneakythrow.svg)](https://www.javadoc.io/doc/com.rainerhahnekamp/sneakythrow)\n\nSneakyThrow is a Java library to ignore checked exceptions. You can integrate it using maven:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.rainerhahnekamp\u003c/groupId\u003e\n  \u003cartifactId\u003esneakythrow\u003c/artifactId\u003e\n  \u003cversion\u003e1.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n![SneakyThrow Usage GIF](https://github.com/rainerhahnekamp/sneakythrow/blob/master/ezgif-3-db5218262c.gif)\n\n\n## Usage\n\nWithout SneakyThrow:\n```java\nURL url;\ntry {\n  url = new URL(\"https://www.hahnekamp.com\");\n} catch (MalformedURLException mue) {\n  throw new RuntimeException(mue);\n}\n```\nWith SneakyThrow:\n```java\nURL url = sneak(() -\u003e new URL(\"https://www.hahnekamp.com\"));\n```\n## Usage with Java 8 Streams\n```java\nprivate URL createURL(String url) throws MalformedURLException {\n  return new URL(url);\n}\n```\n\nThe function above used within a Stream without SneakyThrow:\n```java\nStream\n  .of(\"https://www.hahnekamp.com\", \"https://www.austria.info\")\n  .map(url -\u003e {\n    try {\n      return this.createURL(url);\n    } catch (MalformedURLException mue) {\n      throw new RuntimeException(mue);\n    }\n  })  \n  .collect(Collectors.toList());\n```\nAgain with SneakyThrow:\n\n```java\nStream\n  .of(\"https://www.hahnekamp.com\", \"https://www.austria.info\")\n  .map(sneaked(this::createURL))\n  .collect(Collectors.toList());\n```\nThe static method `sneaked` wraps each function, that has the same signature as a functional interface (java.util.functional).\n\n**Please note the difference between `sneak` and `sneaked`.**\n## How it works\n\nThis project is heavily influenced by [ThrowingFunction](https://github.com/pivovarit/ThrowingFunction). \n\nIn SneakyThrow, each functional interface, defined in `java.util.function`, has an equivalent one with the same signature. The only difference is, that these \"Sneaky Functional Interfaces\" throw exceptions. This gives us the possibility to write lambdas or similar code that also throws exceptions.\n\nBoth `sneak` and `sneaked` wrap the passed \"Sneaky Functional Interfaces\" into a try/catch clause and return the equivalent `java.util.function` interface. In the case of `sneak`, execution and the return of the result is done immediately. \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainerhahnekamp%2Fsneakythrow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frainerhahnekamp%2Fsneakythrow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainerhahnekamp%2Fsneakythrow/lists"}