<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mardy (Posts about securitate)</title><link>http://mardy.it/</link><description></description><atom:link href="http://mardy.it/categories/securitate.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:info@mardy.it"&gt;Alberto Mardegan&lt;/a&gt; </copyright><lastBuildDate>Sat, 11 Apr 2026 13:53:52 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Error handling and exceptions</title><link>http://mardy.it/blog/2020/04/error-handling-and-exceptions.html</link><dc:creator>Alberto Mardegan</dc:creator><description>&lt;p&gt;Yes, this is yet another post in the internet talking about using exceptions
versus error returns. The topic has been flaming up at my workplace for quite
some time now, and I felt that writing a blog post about it during the week-end
would help me focus my thoughts and give me time to explain my point with the
due care. In case you didn't know, I'm against using exceptions for error
handling (maybe having spent many years working with Qt has had an effect on
this); that does not mean that I never write code using exceptions: I certainly
do my good share of &lt;code&gt;try&lt;/code&gt; ... &lt;code&gt;catch&lt;/code&gt; when dealing with third-party code
(including the STL), but you won't find a &lt;code&gt;throw&lt;/code&gt; in my programs.&lt;/p&gt;
&lt;p&gt;I'm not going to write here &lt;em&gt;all&lt;/em&gt; the reasons why I refrain myself from
implementing error handling using exceptions; I'd rather like to focus on the
one I consider to be the major one, and which I rarely see being given the due
weight in the debate.&lt;/p&gt;
&lt;p&gt;And please note that &lt;strong&gt;this post is about C++ only&lt;/strong&gt;; it may be that exception
handling in other languages is designed in such a way that all my concerns are
addressed (either by the language itself, or by common error handling
policies).&lt;/p&gt;
&lt;h2&gt;Code safety&lt;/h2&gt;
&lt;p&gt;I was about to title this “Code readability”, but this is more about code
&lt;em&gt;verifiability&lt;/em&gt;, that is making sure that the code is correct and, ultimately,
safe. As we all know, code is written once but read many times, and even if
it's code you've written yourself, chances are that in a few weeks time you'll
have forgotten several details about it; error cases and error handling are one
typical thing that doesn't stick in our memory for long.&lt;/p&gt;
&lt;p&gt;When I look at a small piece of code, such as the one that can fit into my
screen, or which I can read from a merge request diff, I want to be able to
ascertain that the code I'm looking at is correct. Let's look at some examples.&lt;/p&gt;
&lt;h3&gt;A &lt;code&gt;throw&lt;/code&gt;-free project&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;Car&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setMaximumSpeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Herbie"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executeLap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Car failed to complete track"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GPX path could not be retrieved"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;engineTemperature&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I just made this up, so please bear with me if it doesn't make any sense. What
I want to show is that code like the above has very few fault risks, &lt;em&gt;if found
in a project which bans throwing errors as exceptions&lt;/em&gt;: if we exclude
out-of-memory errors, that are generally not handled to let the
application crash (though you can always catch them if you like), the reader can
easily verify that this code is safe. Coding style policies and naming
conventions can guarantee that &lt;code&gt;setMaximumSpeed()&lt;/code&gt; and &lt;code&gt;setName()&lt;/code&gt; won't have a
return value that needs to be checked, and all other method calls either return
an error that our code is properly handling, or return some value. Of course,
by just looking at this piece of code we cannot know if the
&lt;code&gt;engineTemperature()&lt;/code&gt; method has some other overloaded sibling which accepts
passing a reference to a boolean and which could be used to detect an error;
so, it may be that our code could be improved in that respect, if we had a look
at the header files for the &lt;code&gt;Car&lt;/code&gt; class — but this does deny the fact that a
simple glance at this snippet tells us exactly what errors are handled and what
could be going wrong.&lt;/p&gt;
&lt;p&gt;Let's look at this code instead:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;Car&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setMaximumSpeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Herbie"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executeLap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;engineTemperature&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If we continue on the assumption that we are working on a project which bans
throwing exceptions, we can immediately say that this code is not safe: we
don't know if the car successfully executed a lap on the track, and our process
will crash if &lt;code&gt;boundingRectArea()&lt;/code&gt; is invoked on a null object.&lt;/p&gt;
&lt;h3&gt;Enter the exception&lt;/h3&gt;
&lt;p&gt;In a project where exceptions are actively used, the code from the second
snippet is not obviously wrong anymore: maybe &lt;code&gt;executeLap()&lt;/code&gt; cannot throw any
exceptions, or, if does, the caller of this snippet is catching the exception?
In order to figure out whether this code is correct, I need to see the
declaration of the &lt;code&gt;executeLap()&lt;/code&gt; method, and hope that there's a nice
&lt;code&gt;noexcept&lt;/code&gt; in there; if there isn't, I have to look at its implementation, and
recursively descend through all the methods it calls — at which point the safest
attitude is just to assume that it can throw. But that's only half of the
story, because once I accept the fact that &lt;code&gt;executeLap()&lt;/code&gt; can throw, I need to
check whether the exception is properly handled: I have to check the
implementation of all the callers of my method, and if I don't find a &lt;code&gt;catch&lt;/code&gt;
there, I'll have to recursively walk up the tree of their callers.&lt;/p&gt;
&lt;p&gt;And indeed even the first snippet, which looked so harmless when exception
throwing was banned, suddenly becomes not obviously correct anymore: what if
&lt;code&gt;executeLap()&lt;/code&gt; or &lt;code&gt;getPath()&lt;/code&gt; &lt;em&gt;also&lt;/em&gt; throw an exception? You might say that it
would be quite a silly thing to do, and I'd certainly agree; but it may be that
indeed they don't throw any exceptions in their implementation, but some of the
methods they call does.&lt;/p&gt;
&lt;h3&gt;A compromise: catch early, catch often&lt;/h3&gt;
&lt;p&gt;The obvious solution to the above issue is having a policy of handling
exceptions right away, and explicitly rethrowing them (or even better, rethrow
a different, more appropriate exception) up the stack:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;Car&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setMaximumSpeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Herbie"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executeLap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;engineTemperature&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;boundingRectArea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;runtime_error&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Car failed to complete track"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What I can tell from the above snippet is that the code is handling errors, and
this is somehow a relief. I'm sure some of you would suggest using a more
specific catch clause, but for the sake of this example let's assume that this
one is fine.&lt;/p&gt;
&lt;p&gt;(Quick note: the above example does not catch &lt;code&gt;std::exception&lt;/code&gt;, because that
would also catch the &lt;code&gt;std::bad_alloc&lt;/code&gt; exception which is typically thrown in
out-of-memory situations; my advice is not handle it at all, unless you know
what you are doing)&lt;/p&gt;
&lt;p&gt;In real life, though, you might find that &lt;code&gt;try&lt;/code&gt;-ing on a rather large block of
operations is not enough: suppose that the Car methods all emit the same
exception type, and that you need to handle them differently depending on
&lt;em&gt;when&lt;/em&gt; they occur. Then you'd need to split up the &lt;code&gt;try&lt;/code&gt; into smaller blocks,
and at that point your code won't look any cleaner than the equivalent code
which uses &lt;code&gt;if&lt;/code&gt;s on return values. Of course if you own the Car class you could
modify it to throw different exceptions, in order to keep more operations
inside the &lt;code&gt;try&lt;/code&gt; block and have specific catches at the end.&lt;/p&gt;
&lt;h3&gt;The big catch (pun intended)&lt;/h3&gt;
&lt;p&gt;Even once you've refactored your methods to get the best out of exceptions
(where "best" is highly subjective, but let's assume that it just means that
you are happy with your exception-throwing code), there's something that still
bothers me, and that's exactly the same thing that proponents of exceptions
use as a “pro” in their argumentations: the business logic of your code gets
separated from the error handling.  You get a nice block of pure logic, not
cluttered with error checking, and a catch section (which I call “the big
catch”) where error cases are handled.&lt;/p&gt;
&lt;p&gt;I really don't see how that makes the code any more readable or safe: sure, the
logic is not intertwined with error handling and might help focus on the
expected flow of the operations (though, really, I do not think that normal
brains have a problem skipping over &lt;code&gt;if&lt;/code&gt; blocks), but that's hardly what I'm
interested in when I want to check that the code is correct. Most of program
errors and bugs lie in handling the edge cases and the abnormal situations, the
seldomly taken code paths, and that's where I need to focus my attention.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;operationA&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;operationB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;operationC&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;operationD&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ExceptionI&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ExceptionII&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ExceptionIII&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;runtime_error&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;When I see code like this one, I need to mentally build a mapping of
“&lt;code&gt;operationX()&lt;/code&gt; → possible exceptions” (which, unless exception naming is
making this obvious, requires me to look at the implementation of the
&lt;code&gt;operationX()&lt;/code&gt; functions), and then mentally reconstruct the possible code
paths in case &lt;code&gt;operationX()&lt;/code&gt; fails, for each line of the &lt;code&gt;try&lt;/code&gt; block.&lt;/p&gt;
&lt;p&gt;Not seeing the errors &lt;em&gt;right there, right away&lt;/em&gt; makes the correctness
verification &lt;em&gt;harder&lt;/em&gt;, which in turns means that the code becomes less safe. It
will make you focus on the best case scenario, while ignoring all those
annoying edge cases — too bad that 90% of the bugs are there.&lt;/p&gt;
&lt;h2&gt;Reading through the ISO C++ &lt;del&gt;propaganda&lt;/del&gt; FAQ&lt;/h2&gt;
&lt;p&gt;I've been given a link to the &lt;a href="https://isocpp.org/wiki/faq/exceptions"&gt;C++ FAQ about
exceptions&lt;/a&gt;, and unfortunately I read
it. While there isn't much to argue on the technical side of it, it also
carries some misleading statements, which might be true in absolute terms but
don't let you see the big picture by not mentioning all that you need to know
(which is the fundamental technique behind propaganda). An example is when they
mention that eliminating ifs makes for more robust code, without mentioning
that the same applies to all code branches, including exceptions.&lt;/p&gt;
&lt;p&gt;Another argument that bothered me when I read it is the one about error
propagation; this is the example they make:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f1&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;f2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;some_exception&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// ...code that handles the error...&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f2&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f3&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f3&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f4&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f4&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f5&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f5&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f6&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f6&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f7&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f7&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f8&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f8&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f9&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f9&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;f10&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f10&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cm"&gt;/*...some error condition...*/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;some_exception&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The claim is that this code is more readable than the one with explicit error
handling, because all the &lt;code&gt;f2()&lt;/code&gt;, &lt;code&gt;f3&lt;/code&gt;, …, &lt;code&gt;f9()&lt;/code&gt; functions don't have to
handle the error occurring in &lt;code&gt;f10()&lt;/code&gt;. It is indeed a convincing argument,
when presented in these terms, but is this really how our code looks like?  In
real life, you'll hardly have a chain of 1-liner functions, all defined next
to each other in the same file. The moment that you realize that each one of
these &lt;code&gt;f&lt;sub&gt;&lt;i&gt;n&lt;/i&gt;&lt;/sub&gt;()&lt;/code&gt; functions might be twenty or thirty
lines long, and that they might be scattered over different files, and be
called not just by &lt;code&gt;f&lt;sub&gt;&lt;i&gt;n-1&lt;/i&gt;&lt;/sub&gt;()&lt;/code&gt; but by any other
function in the codebase, the picture does not look so rosy anymore: we get
back to my main point of pain, that is that looking at the code of, say,
&lt;code&gt;f5()&lt;/code&gt;, I will not be able to tell if the errors thrown by it, or by any of the
methods invoked by it, are properly handled.&lt;/p&gt;
&lt;h2&gt;Exceptions in APIs&lt;/h2&gt;
&lt;p&gt;A side note about projects using exceptions. I'm not really bothered when a
library I need to use is throwing exceptions: having to write&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://example.com/resource.txt"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;is not less readable or less safe than the code I'd write if &lt;code&gt;Foo::fetch()&lt;/code&gt;
returned an error code. I still do have a little complaint, because the library
author has given himself the right to decide that a failure in his library
should be considered a critical fault, whereas it may be that in my program it
is an expected failure and using exceptions imposes a penalty which could have
been avoided. But I digress.&lt;/p&gt;
&lt;p&gt;As long as the library documents which exceptions are thrown, it is used by many
people (which hopefully means that it has few bugs) and it is a library that I
don't need to contribute to, wrapping some of its methods in &lt;code&gt;try&lt;/code&gt; blocks is
something I can live with.&lt;/p&gt;
&lt;p&gt;One situation where I actually wish that libraries threw an exception is in
out-of-memory situations; in that case, of course, I'd expect them to throw
nothing else than &lt;code&gt;std::bad_alloc&lt;/code&gt;, which is the exception emitted by the
standard library in such situations. That allows the caller to decide whether
to ignore the exception and have the process terminated (which is what I
usually do, at least in desktop applications) or try their luck and handle the
failure — the latter is not easy, but it can certainly be done.&lt;/p&gt;
&lt;p&gt;This is one case where error returns can be problematic, because it's likely
that your code would look something like&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c1"&gt;// suppose that this returns Error::OutOfMemory&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to open "&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and in this case there's actually a risk that &lt;em&gt;your code&lt;/em&gt; is going to trigger
an out-of-memory error in logging the message; this shouldn't be a concern in
most cases, but I can imagine some situations where one might want to know
which was the exact operation that first incurred in the out-of-memory failure.&lt;/p&gt;
&lt;p&gt;So, I'm actually fine with &lt;code&gt;new&lt;/code&gt; throwing. As for my code, my &lt;code&gt;throw&lt;/code&gt; statement
is actually spelt as &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;</description><category>english</category><category>informatica</category><category>kdeplanet</category><category>planetmaemo</category><category>programmation</category><category>Qt</category><category>securitate</category><guid>http://mardy.it/blog/2020/04/error-handling-and-exceptions.html</guid><pubDate>Fri, 24 Apr 2020 15:07:51 GMT</pubDate></item><item><title>Looking out for ideas: federated / aggregated content</title><link>http://mardy.it/blog/2019/07/looking-out-for-ideas-federated-aggregated-content.html</link><dc:creator>Alberto Mardegan</dc:creator><description>&lt;p&gt;I was looking at TripAdvisor, some days ago. It's a very useful site, filled
with user-generated advice and reviews, which has become almost a must for
travellers.  But I never like it when a private entity gets so much power over
our lives (even if it's — &lt;strong&gt;currently&lt;/strong&gt; — exercised in total fairness).&lt;/p&gt;
&lt;p&gt;I would like to have a &lt;em&gt;federated&lt;/em&gt; TripAdvisor-like network. I duckduckwent for
a while, but I didn't find anything similar (if you know of some project of
that kind, please let me know in the comments).&lt;/p&gt;
&lt;p&gt;But thinking more about the issue, I realised that I probably wouldn't even
bother to type my reviews into that site; I have a blog, so ideally I would
like to have the option to write my review here, and then have the site import
it. Technically, it could work with a webhook, or even a periodic check
(real-time updates would not be a requirement here) over a URL I've linked to
in my profile on that site. Then, in order for the posts to be imported, they
would have to be entered in a standard format: maybe some keywords (or
invisible HTML elements) could be used as markers for the content that need to
be extracted from an otherwise ordinary blog post, or the relevant content
could be replicated in a different format in the HTML headers (this, though,
would require some additional work).&lt;/p&gt;
&lt;p&gt;And while we are at it, why not extend this to other social networks? I use
&lt;a href="https://soc.ialis.me/@mardy"&gt;Mastodon&lt;/a&gt;, for example, and occasionally I send
out a &lt;em&gt;toot&lt;/em&gt; with a link to my latest blog post in there. But it would be much
nicer if I could somehow set a special mark into my posts while composing them,
to have them automatically &lt;em&gt;tooted&lt;/em&gt; out on my account (this could probably be
implemented as a standalone service, authorized to act on my Mastodon account —
similarly to how the &lt;a href="https://crossposter.masto.donte.com.br/"&gt;Mastodon-Twitter crossposter
app&lt;/a&gt; works).&lt;/p&gt;
&lt;p&gt;But I'm rather confident that I'm not the only one having this kind of needs,
and that's why I'm writing this blog post: maybe someone out there has already
found a solution, or has some more concrete ideas? If so, I'm all eyes!&lt;/p&gt;</description><category>english</category><category>informatica</category><category>kdeplanet</category><category>planetmaemo</category><category>programmation</category><category>reflexiones</category><category>securitate</category><guid>http://mardy.it/blog/2019/07/looking-out-for-ideas-federated-aggregated-content.html</guid><pubDate>Wed, 17 Jul 2019 14:55:04 GMT</pubDate></item><item><title>Why you shouldn't encrypt all your private communications</title><link>http://mardy.it/blog/2018/11/why-you-shouldnt-encrypt-all-your.html</link><dc:creator>Alberto Mardegan</dc:creator><description>&lt;p&gt;I was at the &lt;a href="https://linuxpiter.com/en"&gt;LinuxPiter conference&lt;/a&gt; a couple of weeks ago, and among the many interesting talks, a couple were about cybersecurity, privacy, encryption.
The main point of these talks was roughly this: end-to-end encryption is getting easier to setup, so we (the technical audience at the conference) can start protecting all our private communication and hopefully help bringing the technology to a state where it's more accessible to the masses.&lt;/p&gt;

&lt;center&gt;
&lt;a data-flickr-embed="true" href="https://www.flickr.com/photos/jdandersonglobal/15083897257/" title="Cyber Security"&gt;&lt;img src="https://farm6.staticflickr.com/5566/15083897257_d5e4dc1a26_z.jpg" width="640" height="427" alt="Cyber Security"&gt;&lt;/a&gt;&lt;script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"&gt;&lt;/script&gt;
&lt;/center&gt;

&lt;p&gt;The reasons why people want to encrypt their private communications are varied: sometimes it's about hiding one's communications away from an oppressive government or from big corporations; other times it's about avoiding personality theft or stalking; but in general, the core point is that &lt;em&gt;it's my private communication&lt;/em&gt;, and no other eyes than mine and the intended receivers's should have any right to see it. And this sounds pretty reasonable indeed.&lt;/p&gt;

&lt;p&gt;However, some reading into the history of the technologies used to achieve this result has left me doubting. And actually, as this article's title says, I've slowly grown convinced that I should fight the battle on the opposite front, and convince people not to pursue the goal of encrypting their private digital lives. Which will probably get you suspecting that I've gone out of my mind, to propose not supporting something that nearly the entire technical community recognizes as valuable. But if you bear with me a little longer, I'll try to explain.&lt;/p&gt;

&lt;p&gt;Let's start with this quote by Edward Snowden:&lt;br&gt;

&lt;/p&gt;&lt;div style="margin: 0 auto; width: 90%"&gt;
&lt;blockquote&gt;
“Arguing that you don't care about the right to privacy because you have nothing to hide is no different than saying you don't care about free speech because you have nothing to say.”
&lt;/blockquote&gt;
&lt;/div&gt;

&lt;p&gt;I do care about my privacy and, furthermore, I'm not such a hypocrite to say that I don't have anything to hide: quite the opposite, there are plenty of things I don't want people to know about me. I'm not arguing against the right to one's privacy, and &lt;em&gt;I do use encryption&lt;/em&gt; when storing sensitive data on my computer or when sending out passwords to people. And I've long stopped sharing bits of my private life on the big social networks, which I mostly use in &lt;i&gt;write-only&lt;/i&gt; mode for spreading political propaganda (and I invite you to do the same, unless you have already left them: these places must die). What I am objecting to is &lt;em&gt;mass&lt;/em&gt; encryption of all of your communications, just for the sake of making them inaccessible to everyone else.&lt;/p&gt;

&lt;p&gt;I don't want to hide things from the government. I definitely want to hide as much as possible from corporations and other individuals, but I do want the state officials to be able to access any private conversation of any citizen. I do not want mass surveillance, but if there are serious reasons to suspect that a person could be involved in some crime, then I want the state to be able to look into the suspect's conversations — while exercising maximum care so that these are not leaked to the press and, in general, to people who don't need to know about them. Call me naive or an idealist, I still hold the state responsible for my own safety and the sole guarantor of justice. Should state officials abuse their position and either leak the private communications of the citizens or — worse — use them for blackmailing, this is something that should be investigated and punished, but I don't believe that it is the norm. Considering Snowden's revelations about the extent of the mass surveillance program in the U.S. and seeing how little of this information has been revealed or used by malicious state officials makes me optimistic in thinking that this is a secondary problem.&lt;/p&gt;

&lt;p&gt;Surely someone could point out that not all governments are trustworthy: totalitarian regimes suppress dissent, while encryption could help the oppressed speak freely and organize themselves. The first part of the sentence is certainly true, but the second part reveals, in my opinion, a wrong evaluation of the reactionary movements. Let me explain it more clearly with one example.&lt;br&gt;
My western readers would probably include Russia (the country in which I live) in the list of the “totalitarian regimes” I mentioned above; but you might be surprised to know that the West's favourite opposition character, the nationalist &lt;a href="https://en.wikipedia.org/wiki/Alexei_Navalny"&gt;Alexei Navalny&lt;/a&gt;, who is getting jailed every other month for minor offences, is quite open in his criticism, and provocatively organizes actions that he knows will get him into trouble, with the goal of getting maximum visibility and exposing what he believes are unreasonable laws. If on one side there could be some value for revolutionaries to use encrypted communications during the initial phases of their action, on the other, the real change can only be brought forward with the involvement of the masses — which means one needs &lt;em&gt;open talks&lt;/em&gt;.&lt;br&gt;
And even if we limit ourselves to the early phases of the organisation of a reactionary plan, I do believe that using encryption carries the bigger risk of alienating one's potential allies, which were not part of the conversation, who might easily be led to believe (the conversation not having been released) that the participants in these secret talks were after some criminal plan or were getting support from some foreign country.&lt;/p&gt;

&lt;div style="margin: 0 auto; width: 80%"&gt;
&lt;center&gt;
&lt;a data-flickr-embed="true" href="https://www.flickr.com/photos/kenpower/4900658261/" title="Beijing Airport"&gt;&lt;img src="https://farm5.staticflickr.com/4123/4900658261_87fa1a6f58_z.jpg" width="640" height="427" alt="Beijing Airport"&gt;&lt;/a&gt;&lt;script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"&gt;&lt;/script&gt;
&lt;/center&gt;
&lt;caption&gt;Picture this: at the airport security check (maybe in a country whose government you don't trust the least), you are asked permission by the officials to open your luggage for a search. If you refuse, they'll confiscate your luggage, but they'll let you return home free; if you agree, you'll be able to return home free, and with your luggage.&lt;/caption&gt;
&lt;/div&gt;

&lt;p&gt;And we get to the real criminals. No matter how some politicians are abusing the topic for their own profit, it remains a fact that terrorism exists and terrorists operate in our cities. If we all encrypt our conversations, we practically preclude the security services from performing a screening which could help them focus their attention on potential suspects; and whether the terrorists encrypt their conversations has little impact: the very fact that a conversation is encrypted could raise some suspicion (which doesn't mean that the security services would hunt down everyone who uses encryption! — but their online behaviour could be monitored for some time).&lt;br&gt;
Furthermore, I don't buy the story that these technologies are good because they can help those who fight against injustices in some remote oppressive country; on the contrary, I have a strong suspicion that the reason why these technologies are pushed forward it to protect the corrupted financial world from having their deeds exposed, here at home. Well, maybe that's not the goal, but indeed those people would benefit from it, at our expense.&lt;/p&gt;

&lt;p&gt;Finally, let me spend a couple of words on encryption technologies, because I believe that their history matters and that we should be aware of who stands behind them. Suppose that you were a Russian dissident, and the &lt;a href="https://en.wikipedia.org/wiki/Main_Intelligence_Directorate"&gt;GRU&lt;/a&gt; sponsored the development of some technology that promises full anonymity and secrecy; would you use it? I hope you agree with me, if I say that you'd have to be a complete fool to use it, no matter how many independent agencies have analyzed the technology and found it to be impenetrable. The lamb would never live in a house built for him by the wolf, no matter how comfortable or solid it looks like.&lt;br&gt;
That's why, if I had to name one particular privacy enabling technology which I recommend you &lt;em&gt;not&lt;/em&gt; to use, that would be &lt;a href="https://en.wikipedia.org/wiki/Tor_%28anonymity_network%29"&gt;Tor&lt;/a&gt;. Developed in the '90s by the U.S. Navy to be used by U.S. intelligence agents embedded in foreign countries, the Tor project is still being funded by the U.S. government and its usage is being promoted worldwide, in order to make it harder for foreign government to identify the American agents; because it goes without saying that, if the U.S. agents were the only people using Tor, then foreign security services would have a rather easy time spotting them.
Now, if you are perfectly fine with the U.S. government being able to read your secret communications, by all means do feel welcome to use Tor. But if you are a dissident in either the U.S. or an allied country, be it a Western European country, Japan, Israel or Saudi Arabia, then I'd think twice before using it. And even if you lived in Russia, China or Iran, well, the same fact of connecting to Tor carries the potential risk of exposing you as a rebel or as a foreign agent.&lt;/p&gt;

&lt;p&gt;That's why I don't encrypt my online conversations, and I don't strive to be anonymous online. No matter how bad the government we live in might be, I'm deeply convinced that the state is the only authority that can protect us; and if we don't trust it, or if we want to act against it, then we'd rather do it openly, suffering all the consequences that might arise, but having done all our best so that other people might find the courage to join our cause.&lt;/p&gt;</description><category>english</category><category>politica</category><category>securitate</category><guid>http://mardy.it/blog/2018/11/why-you-shouldnt-encrypt-all-your.html</guid><pubDate>Tue, 20 Nov 2018 17:18:00 GMT</pubDate></item></channel></rss>