What you must know about PHP errors to avoid scratching your forehead when something goes wrong

While pure object-oriented languages produce mainly exceptions to signal an error, PHP started out as procedural and so it has a wide range of errors that can be raised along with exceptions.

Errors are Human, But We Must Identify Them

There isn’t a programmer alive who hasn’t made errors when coding something at some point in their career. It is simply a part of the process, and it is important to recognize that we will all make these types of mistakes from time to time. That said, it is best to identify the errors as they occur so as to correct them at the moment. 

Avoid Yoda Conditions in Perl You Should

I remember a brief time in the mid-2000s insisting on so-called “Yoda conditions” in my Perl. I would place constants to the left of equality comparisons. In case I accidentally typed a single = instead of ==, the compiler would catch it instead of blithely assigning a variable. For example:

Perl
 
if ( $foo == 42 ) { ... } # don’t do this
if ( 42 == $foo ) { ... } # do this
if ( $foo = 42  ) { ... } # to prevent this

And, because a foolish consistency is the hobgoblin of little minds, I would even extend this to string and relational comparisons.

Sweeter Perl Exception Classes

I mentioned at the Ephemeral Miniconf last month that as soon as I write about one Perl module (or five), someone inevitably brings up another (or seven) I’ve missed. And, of course, it happened again last week. No sooner had I written in passing that I was using Exception::Class than the denizens of the Libera Chat IRC #perl channel insisted I should use Throwable instead for defining my exceptions. I’ve already blogged about various ways of catching exceptions.

Why Throwable? Aside from Exception::Class’s author recommending it over his own work due to a “nicer, more modern interface,” Throwable is a Moo role, so it’s composable into classes along with other roles instead of mucking about with multiple inheritances. This means that if your exceptions need to do something reusable in your application like logging, you can also consume a role that does that and not have so much duplicate code. If you're wondering, no, I’m not going to pick a favorite logging module; I’ll probably get that wrong too.

We Should Write Java Code Differently

For the last few years, I’m writing articles that describe a new, more functional way to write Java code. But the question of why we should use this new coding style remains largely unanswered. This article is an attempt to fill this gap.

Just like any other language, Java evolves over time. So does the style in which Java code is written. Code written around Y2K is significantly different from code written after 2004-2006 when Java5 and then Java6 was released. Generics and annotations are so widespread now, that it’s hard to even imagine Java code without them.

Perl Can Escape the Lisp Curse

Ten years ago Rudolf Winestock wrote The Lisp Curse, an essay that "attempt[ed] to reconcile the power of the Lisp programming language with the inability of the Lisp community to reproduce their pre- AI Winter achievements."

His conclusion? The power and expressiveness of Lisp have conspired to keep its developers individually productive, but collectively unable to organize their work into complete, standardized, well-documented, ‑tested, and ‑maintained packages that they could coalesce into interoperable and widely-adopted solutions. Everything from object systems to types to asynchronous non-blocking programming and concurrency is up for grabs and has multiple competing implementations.

Exception Handling With Try-With-Resource Suppressed Exceptions

Learn more about different forms of exception handling with the try-with-resource suppressed exception.

In this article, we are going to deal with multiple cases of exception handling with and without the try-with-resources feature in Java.  For details about try-with-resources, please refer to the Oracle docs

You may also like: 9 Best Practices to Handle Exceptions in Java

Below are the cases we will discuss:

Testing Exceptions in Kotlin With assertFailsWith

I wanted to write this short post to highlight the assertFailsWith function available to Kotlin that makes testing exceptions a bit easier. Testing exceptions isn’t something fancy or new to JVM languages (from now on, I will use Java for comparisons), but Kotlin comes with the nice extra benefit of providing this functionality as part of its standard library. Comparing this to Java, you are likely to bring AssertJ into the mix to achieve similar results.

The main purpose of this post is to make you aware of the assertFailsWith function. I personally did not know it existed for a while and defaulted to depending on AssertJ. Not that I have anything against AssertJ that is. There are many other features that the library provides, but for this specific instance, it might be possible to remove it (assuming you are not using it for anything else that is).

Spring REST Service Exception Handling

This tutorial talks about Spring Rest Service Exception Handling. In our previous article, we created our very first Spring Boot REST Web Service. In this tutorial, let’s concentrate on how to handle an exception in Spring applications. While there always is an option to handle them manually and set a particular ResponseStatus, however, Spring provides an abstraction over the entire exception handling and just asks you to put a few annotations — it takes care of everything else. In this article, we will demonstrate these concepts with code examples.

How to Manually Handle Exceptions

In the Spring Boot Rest Service tutorials, we had created a Dogs Service to understand the concepts. In this post, let's extend the same Dogs Service to handle exceptions.