{"id":12,"date":"2022-11-11T05:07:11","date_gmt":"2022-11-11T05:07:11","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/eberman\/?p=12"},"modified":"2022-11-11T05:07:11","modified_gmt":"2022-11-11T05:07:11","slug":"error-handling-in-rust","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/eberman\/2022\/11\/11\/error-handling-in-rust\/","title":{"rendered":"Error Handling in Rust"},"content":{"rendered":"\n<p>After writing about Rust in my second blog post, and given the fact that I am still working on picking up the language, I figured I would do the final blog post on error handling in Rust. <\/p>\n\n\n\n<p>Most languages only provide one way to handle errors. They usually will throw an exception associated with a particular type of error &#8211; such as a Syntax Error, Type Error, etc. Error handling in Rust is unique in that it is subdivided into two different types of errors &#8211; recoverable and unrecoverable. Recoverable errors are utilized for occurrences such as file input where the program should re-prompt the user for another filename if the file does not exist, or the file permissions do not allow access for that user. The program does not crash, but will handle the error gracefully. Alternatively, unrecoverable errors are reserved for occurences where the program should crash, like when an out of bounds index is attempted to be accessed. Given Rust&#8217;s strong typing and general scope of errors, like most other languages, it will catch the error, print the error to the console, and exit the program. Though this is the cast for most cases, there will be times where the developer may want to product an unrecoverable error in order to avoid instances such as accepting invalid data or when working with an external API that the developer has no control over. <\/p>\n\n\n\n<p>Overall, I really like the approach that Rust has taken to approaching error handling and by breaking it up into two different types of errors it makes the concept of error handling more digestible. I look forward to seeing how to best utilize both recoverable and unrecoverable errors in my Rust journey.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After writing about Rust in my second blog post, and given the fact that I am still working on picking up the language, I figured I would do the final blog post on error handling in Rust. Most languages only provide one way to handle errors. They usually will throw an exception associated with a [&hellip;]<\/p>\n","protected":false},"author":12869,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/users\/12869"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":13,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/posts\/12\/revisions\/13"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/eberman\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}