<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditya Yadav on Medium]]></title>
        <description><![CDATA[Stories by Aditya Yadav on Medium]]></description>
        <link>https://medium.com/@unitedaditya?source=rss-1a28750a715d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lo_Nif9xpn4jsgp5.jpg</url>
            <title>Stories by Aditya Yadav on Medium</title>
            <link>https://medium.com/@unitedaditya?source=rss-1a28750a715d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:32:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@unitedaditya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Error Handling for noobs (Swift 3)]]></title>
            <link>https://medium.com/@unitedaditya/error-handling-for-noobs-swift-3-c4983ab9aaf4?source=rss-1a28750a715d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4983ab9aaf4</guid>
            <category><![CDATA[xcode-8]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[error-handling-concept]]></category>
            <dc:creator><![CDATA[Aditya Yadav]]></dc:creator>
            <pubDate>Thu, 11 May 2017 14:15:59 GMT</pubDate>
            <atom:updated>2017-05-22T04:48:45.845Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*CmFws20CZ_y836wTIiRwxQ.jpeg" /><figcaption>Create Error Handling System for a Bugatti</figcaption></figure><p>Imagine you are the chief Engineer at Bugatti and your team approaches you with a horrendous problem.</p><p><strong>The problem?</strong></p><p>The TOP-SPEED of the car 🚗 is so high that the car has to warn the users after it reaches a certain speed limit , it even has to warn users when they are going too slow.</p><p>You grab your machine , fire up xcode and solve the problem.</p><p><strong>Step 1 :</strong></p><p>We have create situations where the error might occur.</p><p>The error will occour when the speed is above 200 Kmph for going too fast or the error will happen when the car is running at merely 15 Kmph.</p><p>What we do?</p><p>we will create an enum which will be and Error type which will have the errors.</p><p>//Step 1 :</p><blockquote>enum SpeedLimit : Error {</blockquote><blockquote>case tooHigh</blockquote><blockquote>case tooLow</blockquote><blockquote>}</blockquote><p><strong>Step : 2</strong></p><p>Create a function where the error is actually going to happen</p><p>//Step 2 :</p><blockquote>func getCarSpeed(currentSpeed : Int){</blockquote><blockquote>if currentSpeed &gt; 250 {</blockquote><blockquote>} else if currentSpeed &lt; 15 {</blockquote><blockquote>} }</blockquote><p>We write a basic function where we get the current speed of the car and we have the conditions which will be called when the speed reaches any limit.</p><p>Now we tell the function that it can <strong>throw </strong>an error</p><p>//Step 2 :</p><blockquote>func getCarSpeed(currentSpeed : Int) throws{</blockquote><blockquote>if currentSpeed &gt; 250 {</blockquote><blockquote>throw speedLimit.tooHigh</blockquote><blockquote>} else if currentSpeed &lt; 15 {</blockquote><blockquote>throw.speedLimit.tooLow</blockquote><blockquote>} }</blockquote><p>Here we throw the errors from the enum we created , it code itself tells the whole story. we even add a <strong>throws </strong>which warns you that your function can throw errors , it will even help your teammates understand your code better.</p><p><strong>Step 3:</strong></p><p>Calling the function :</p><p>//Step 3 :</p><blockquote>do {</blockquote><blockquote>try { getCarSpeed(56) } catch SpeedLimit.tooHigh {</blockquote><blockquote>//Handle code here</blockquote><blockquote>print(“Your Speed is too high! Stop.”</blockquote><blockquote>} catch SpeedLimit.tooLow {</blockquote><blockquote>// Handle code here</blockquote><blockquote>print(“You are going to slow!”)</blockquote><blockquote>}</blockquote><p>we use the do block and add the try block inside it to call the function.</p><p>The structure :</p><blockquote>do {</blockquote><blockquote>try (call a function that throws)</blockquote><blockquote>} catch (the error you created) {</blockquote><blockquote>}</blockquote><p>This is how you handle error , and write the handling code in a private block . This also makes it easier for your fellow developers to read your code and make you look classy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4983ab9aaf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>