<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexandre Pontes</title>
    <description>The latest articles on DEV Community by Alexandre Pontes (@apontes77).</description>
    <link>https://dev.to/apontes77</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F400084%2Fe849ca04-e42e-4572-8fd2-67dae4661b6c.jpeg</url>
      <title>DEV Community: Alexandre Pontes</title>
      <link>https://dev.to/apontes77</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apontes77"/>
    <language>en</language>
    <item>
      <title>Provocações sobre um dia ordinário no desenvolvimento de software</title>
      <dc:creator>Alexandre Pontes</dc:creator>
      <pubDate>Thu, 27 Feb 2025 01:39:21 +0000</pubDate>
      <link>https://dev.to/apontes77/provocacoes-sobre-um-dia-ordinario-no-desenvolvimento-de-software-4nop</link>
      <guid>https://dev.to/apontes77/provocacoes-sobre-um-dia-ordinario-no-desenvolvimento-de-software-4nop</guid>
      <description>&lt;p&gt;Olha, programar é interessante para o leigo.&lt;/p&gt;

&lt;p&gt;Para o profissional, é uma descoberta sem fim. E que pode tornar-se entediante.&lt;/p&gt;

&lt;p&gt;Eu sempre curti Ciências, em particular, Matemática e Física. Mas moro num país que não permite que a maior parte de pessoas como eu possam investir em viver disso. Então precisamos dançar conforme a música.&lt;/p&gt;

&lt;p&gt;Programar foi o que sobrou como alternativa de carreira mais rentável no longo prazo.&lt;/p&gt;

&lt;p&gt;Não vou mentir que faz tempo que não tenho brilho nos olhos para enfrentar novos desafios. Chegar a uma espécie de platô de carreira sem ter nem 10 anos de experiência parece ser um discurso baseado em "coitadismo". Mas é verdade. Simples assim.&lt;/p&gt;

&lt;p&gt;Logo, como um adulto, precisamos encarar a vida como ela é e entender o que pode ser feito para tornar os dias menos dolorosos. Talvez não tão prazerosos quanto seria se eu fizesse algo que realmente me fizesse brilhar os olhos. Mas suficientemente interessantes para manter cada raiar do sol com mais propósito. Mais direcionamento. &lt;/p&gt;

&lt;p&gt;Neste interim, me vejo olhando para baixo. Não como alguém desanimado. Mas buscando as raízes. Talvez, se entendermos de onde as coisas vêm, consigamos ter ideias mais sustentáveis e, por assim dizer, mais inspiradoras.&lt;/p&gt;

&lt;p&gt;A vida não pode se resumir a resolver somente problemas dos outros, sabe? De fato, resolver a dos outros nos permite ganhar dinheiro, por exemplo. Princípio básico. Mas, ainda somos seres que pensam. Que se reproduzem. Seja fisicamente, seja no mundo das ideias. As ideias precisam se reproduzir em obras que ecoem nossa personalidade.&lt;/p&gt;

&lt;p&gt;Não vale a pena ser, em vida, como o personagem Brás Cubas, de Machado de Assis. Após morto, escrever suas memórias póstumas de quem gostaria de viver uma vida que valesse a pena ser vivida. &lt;/p&gt;

&lt;p&gt;A vida é aqui e agora.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>backend</category>
    </item>
    <item>
      <title>Thinking about Exceptions</title>
      <dc:creator>Alexandre Pontes</dc:creator>
      <pubDate>Thu, 13 Feb 2025 23:02:20 +0000</pubDate>
      <link>https://dev.to/apontes77/thinking-about-exceptions-gf3</link>
      <guid>https://dev.to/apontes77/thinking-about-exceptions-gf3</guid>
      <description>&lt;h3&gt;
  
  
  Let's Think a Little Bit About Exceptions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What Is an Exception?
&lt;/h4&gt;

&lt;p&gt;An exception is an event that occurs unexpectedly and disrupts the normal flow of a program. We never write code thinking, &lt;em&gt;"This should be a good exception!"&lt;/em&gt; On the contrary, exceptions happen when something goes wrong beyond our control or planning.&lt;/p&gt;

&lt;p&gt;Therefore, handling exceptions properly is crucial to ensuring that our system remains robust and reliable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Checked vs. Unchecked Exceptions
&lt;/h4&gt;

&lt;p&gt;Whether you're using Java or Kotlin, exceptions are an essential part of the language. Let's explore the hierarchy behind exception handling.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Checked Exceptions&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Checked exceptions are exceptions that are verified at compile time. This means that the compiler forces you to handle them either by using a &lt;code&gt;try-catch&lt;/code&gt; block or by propagating them with the &lt;code&gt;throws&lt;/code&gt; keyword. The base class for checked exceptions is &lt;code&gt;Exception&lt;/code&gt; (excluding &lt;code&gt;RuntimeException&lt;/code&gt; and its subclasses).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; &lt;code&gt;IOException&lt;/code&gt;, &lt;code&gt;SQLException&lt;/code&gt;, &lt;code&gt;FileNotFoundException&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Unchecked Exceptions&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Unchecked exceptions occur during runtime and are not checked at compile time. They usually arise due to logical errors in the program, such as accessing a null reference or an invalid index. The base class for unchecked exceptions is &lt;code&gt;RuntimeException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; &lt;code&gt;NullPointerException&lt;/code&gt;, &lt;code&gt;ArrayIndexOutOfBoundsException&lt;/code&gt;, &lt;code&gt;IllegalArgumentException&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Handling and Throwing Exceptions
&lt;/h4&gt;

&lt;p&gt;In Java, you can either handle exceptions directly or propagate them to the caller. Let’s look at both approaches.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Handling Exceptions&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The most common way to handle exceptions is by using a &lt;code&gt;try-catch-finally&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;yourMethod&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
    &lt;span class="c1"&gt;// Additional logic&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Log the stack trace or throw a custom exception&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;CustomException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error executing the method"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Cleanup resources, such as closing files or database connections&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;Best Practice:&lt;/strong&gt; Avoid catching general exceptions like &lt;code&gt;Exception&lt;/code&gt;. Instead, catch specific exceptions to make your error handling more precise.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Throwing Exceptions&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Instead of handling an exception within the method, you can propagate it to the caller using the &lt;code&gt;throws&lt;/code&gt; keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;yourMethod&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Files&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readAllLines&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Paths&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"file.txt"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach allows the calling method to decide how to handle the exception.&lt;/p&gt;

&lt;h4&gt;
  
  
  Unit Test Example
&lt;/h4&gt;

&lt;p&gt;A unit test can validate that a method correctly throws an exception using JUnit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;junit&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;jupiter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;api&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Assertions&lt;/span&gt;&lt;span class="o"&gt;.*;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.junit.jupiter.api.Test&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExceptionTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Test&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testExceptionIsThrown&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ExceptionThrowingClass&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ExceptionThrowingClass&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;assertThrows&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;methodThatThrowsException&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test ensures that &lt;code&gt;methodThatThrowsException&lt;/code&gt; correctly throws an &lt;code&gt;IllegalArgumentException&lt;/code&gt; when executed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Final Thoughts
&lt;/h4&gt;

&lt;p&gt;Handling exceptions properly makes your code more reliable and maintainable. When choosing between checked and unchecked exceptions, think about the best way to communicate failures to users and developers. Also, whenever possible, prefer throwing custom exceptions to make error handling clearer and more meaningful.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>java</category>
      <category>kotlin</category>
      <category>poo</category>
      <category>cleancode</category>
    </item>
  </channel>
</rss>
