{"id":1849,"date":"2009-01-06T12:31:29","date_gmt":"2009-01-06T16:31:29","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=1849"},"modified":"2014-04-15T20:29:11","modified_gmt":"2014-04-16T00:29:11","slug":"abstracting-away-from-exceptions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2009\/01\/06\/abstracting-away-from-exceptions\/","title":{"rendered":"Abstracting Away From Exceptions"},"content":{"rendered":"<p><a href=\"http:\/\/blog.objectmentor.com\/articles\/2009\/01\/05\/abstracting-away-from-exceptions\">Michael Feathers<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/blog.objectmentor.com\/articles\/2009\/01\/05\/abstracting-away-from-exceptions\"><p> Exceptions seem to encourage &ldquo;controlled abort&rdquo; as an error handling policy. You throw an exception, it travels up the stack, and you catch it someplace else. All of your work is unwound (you hope) and then you are left with the task of logging the error or trying something else.<\/p><\/blockquote>\r\n<p>The comments are interesting, too.<\/p>\r\n<p>I think exceptions are especially bad in Cocoa as a way of handling expected errors. Catching them is verbose, so the natural tendency is to do so as little as possible. Secondly, methods don&rsquo;t declare whether they raise exceptions, so there&rsquo;s no easy way to make sure you&rsquo;re catching all the ones you should. <a href=\"http:\/\/developer.apple.com\/documentation\/Cocoa\/Reference\/Foundation\/Classes\/nserror_Class\/Reference\/Reference.html\">NSError<\/a>, ugly though it is, actually seems to be a pretty good system for managing and propagating errors generated by different layers of code and even different languages.<\/p>\r\n<p>Update (2009-01-16): An interesting post from Mark Wooding about <a href=\"http:\/\/groups.google.com\/group\/comp.lang.lisp\/msg\/6157c055503e8ba8\">Lisp conditions vs. exceptions<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Michael Feathers: Exceptions seem to encourage &ldquo;controlled abort&rdquo; as an error handling policy. You throw an exception, it travels up the stack, and you catch it someplace else. All of your work is unwound (you hope) and then you are left with the task of logging the error or trying something else. The comments are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,79,857,54,71],"class_list":["post-1849","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-exceptions","tag-nserror","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=1849"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1849\/revisions"}],"predecessor-version":[{"id":8704,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/1849\/revisions\/8704"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=1849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=1849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=1849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}