<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Exceptions and Logging on kodkod | Intro Course</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/</link><description>Recent content in Exceptions and Logging on kodkod | Intro Course</description><generator>Hugo</generator><language>en</language><copyright>מבואות קודקוד</copyright><atom:link href="https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/index.xml" rel="self" type="application/rss+xml"/><item><title>Exceptions A: Why Error Handling Is Needed, try and except</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/01-try-except/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/01-try-except/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What an &lt;strong&gt;Exception&lt;/strong&gt; is.&lt;/li&gt;
&lt;li&gt;Why real software has to &lt;strong&gt;handle&lt;/strong&gt; errors and not crash.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;try&lt;/code&gt; / &lt;code&gt;except&lt;/code&gt; syntax.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Different&lt;/strong&gt; handling for different kinds of errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Imagine a small calculator server: one client sends &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt; instead of a number, &lt;strong&gt;and the whole server crashes&lt;/strong&gt;. All the clients who come after them get &amp;ldquo;Connection refused&amp;rdquo;.&lt;/p&gt;</description></item><item><title>Exceptions B: else and finally — the Full Structure</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/02-else-finally/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/02-else-finally/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;In the previous lesson we used &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt;. The structure has two more parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;else&lt;/code&gt;&lt;/strong&gt; — runs &lt;strong&gt;only if there was no error&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;finally&lt;/code&gt;&lt;/strong&gt; — runs &lt;strong&gt;always&lt;/strong&gt;, with or without an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Imagine code that opens a connection to a Database (the backend and databases topics), performs an action and closes the connection. What happens if the action fails in the middle? If the closing is written after the action, it &lt;strong&gt;will not be executed&lt;/strong&gt;, and the connection stays open. After a hundred such failures, the server will crash because it ran out of connections.&lt;/p&gt;</description></item><item><title>Exceptions C: raise — Throwing an Error Ourselves</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/03-raise/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/03-raise/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;Until now &lt;strong&gt;Python&lt;/strong&gt; threw errors, and we &lt;strong&gt;caught&lt;/strong&gt; them. Today we will learn to throw them ourselves, with &lt;strong&gt;&lt;code&gt;raise&lt;/code&gt;&lt;/strong&gt;, when our code detects an invalid state.&lt;/p&gt;</description></item><item><title>Logging A: Why print Is Not Logging, and the Log Levels</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/04-logging-basics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/04-logging-basics/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What a &lt;strong&gt;Log&lt;/strong&gt; is and why real systems write one.&lt;/li&gt;
&lt;li&gt;Why &lt;strong&gt;&lt;code&gt;print&lt;/code&gt; is not Logging&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Python&amp;rsquo;s &lt;strong&gt;&lt;code&gt;logging&lt;/code&gt;&lt;/strong&gt; module.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;five levels&lt;/strong&gt; of the log: &lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;info&lt;/code&gt;, &lt;code&gt;warning&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt;, &lt;code&gt;critical&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;The server you will write in the backend and databases topics will run &lt;strong&gt;without anyone watching it&lt;/strong&gt;, maybe on a computer in the cloud, in the middle of the night. Tomorrow morning a customer will say &amp;ldquo;my order disappeared during the night&amp;rdquo;. How will you know what happened?&lt;/p&gt;</description></item><item><title>Logging B: Saving Logs to a File and Recording Important Actions</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/05-logging-to-file/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-errors-logging/05-logging-to-file/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;How to write logs &lt;strong&gt;to a file&lt;/strong&gt;, and not only to the screen.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Writing modes&lt;/strong&gt;: add to the end of the file, or start over.&lt;/li&gt;
&lt;li&gt;How to record an error &lt;strong&gt;with all the details&lt;/strong&gt; (Traceback).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What to record&lt;/strong&gt;: which actions are important and at which level.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Remember the topic on the computer, the operating system and the network? What is on the screen and in memory disappears when the program ends. A &lt;strong&gt;file&lt;/strong&gt; is kept on Storage. A log on the screen helps only whoever is sitting in front of it &lt;strong&gt;now&lt;/strong&gt;. A log in a file can be opened &lt;strong&gt;tomorrow&lt;/strong&gt;, searched, and used to understand what happened during the night.&lt;/p&gt;</description></item></channel></rss>