{"id":874,"date":"2024-09-03T22:32:59","date_gmt":"2024-09-03T17:32:59","guid":{"rendered":"https:\/\/augurytech.co.uk\/courses\/?p=874"},"modified":"2024-10-05T09:04:02","modified_gmt":"2024-10-05T04:04:02","slug":"python-exceptions","status":"publish","type":"post","link":"https:\/\/augurytech.co.uk\/courses\/python\/python-exceptions\/","title":{"rendered":"Python: Exceptions"},"content":{"rendered":"\n<p>Exceptions are run-time errors.<\/p>\n\n\n\n<p>Compile time errors are syntax errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exception Objects<\/h3>\n\n\n\n<p>Python uses special objects called exceptions to manage errors that arise during a program&#8217;s execution.<\/p>\n\n\n\n<p>Whenever an error occurs that makes Python unsure of what to do next, it creates an exception object.<\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Handling Errors \/ Exception<\/h3>\n\n\n\n<p>Exceptions are handled with<strong> try-except <\/strong>blocks. <\/p>\n\n\n\n<p>A <strong>try-except<\/strong> block asks Python to do something, but it also tells Python what to do if an <strong>exception <\/strong>is raised. <\/p>\n\n\n\n<p>When you use <strong>try-except<\/strong> blocks, your programs will continue running even if things start to go wrong.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>try:\n    value1 = int(input(\"enter a number\"))\n    value2 = int(input(\"enter another number\"))\n\n    ans = value1 \/ value2\n\nexcept Exception as e:\n    print(f\"Exception handled >> {(e)}\")<\/em><\/strong><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Exceptions are run-time errors. Compile time errors are syntax errors. Exception Objects Python uses special objects called exceptions to manage errors that arise during a program&#8217;s execution. Whenever an error occurs that makes Python unsure of what to do next, it creates an exception object. Handling Errors \/ Exception Exceptions are handled with try-except blocks. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-python","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5],"tags":[],"class_list":{"0":"post-874","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python"},"_links":{"self":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/comments?post=874"}],"version-history":[{"count":11,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/874\/revisions"}],"predecessor-version":[{"id":887,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/874\/revisions\/887"}],"wp:attachment":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/media?parent=874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/categories?post=874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/tags?post=874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}