Declarations, errors and crashes: what is the difference?

Contents

Failure danger symbol

Computer problems. We all have them sooner or later. Know the ins and outs of errors, affirmations, faults and more is vital to understand more about the problem at hand. Learn all about it.

What is a Claim?

When a developer starts writing code, will soon present if statements in it. a if The statement is used whenever a certain condition needs to be tested. As an example, one could write a pseudocode if next way statement:

if (water_level > high_water_mark) then {
  raise_alert
}

In other words, si el nivel del agua supera la marca alta, se genera una alerta. Pero tal vez el sensor de agua esté roto, por lo tanto actualizamos el código para que coincida:

if (sensor_readout == nonsensical) then {
  raise_error
  fail
}else{
  if (water_level > high_water_mark) then {
    raise_alert
  }
}

Genial, ahora obtendremos un error y fallaremos la rutina si el sensor_readout no tiene sentido. Y solo si el valor demuestra ser sensato (debido a la else clause, In other words, qué hacer en la situación opuesta), proceda a chequear el nivel_agua con la marca_alta_agua.

Despite this, tal vez alguien haya apagado el sensor. We can go on like this for a while. We can cover every possible scenario imaginable and still miss a few. Of course, we could cover all possible situations with a combination else clause and verify that each condition is compared with another, but even in such cases, we could have overlooked some combinations of variables.

Even if we only had a limited set of variables to work with, the number of possible combinations in which a software package can be found is quite numerous. And what is more, this type of if Conditional tests occur fairly regularly in almost all software.

Reasoning a little more about this dilemma, we quickly understand that we (as developers) we could (like all humans we make mistakes) sooner or later introduce code that allows the software to run in undefined territory. The variable x is set to a specific value, the variable and is assigned to another, and there was no provision for this in the code.

This is exactly the situation that a statement can, until a certain point, provide. An affirmation is another condition (think of it as another if statement.) which states if there is a certain strange situation / rare / unplanned / unforeseen and, in general, handles such a situation by stopping the program instead of continuing to run with an undefined state / unknown.

Although the network that will return the asset test is still limited to the intelligence and skills of the developer implementing the assertion, an assertion can often be made longer than the limited limits of if statements that test the state of multiple variables, or it could be made quite specific to avoid certain dangerous situations.

As an example, let's say our little water sensor is mounted in a rain tank. Because, the water should never be boiling. Despite this, if our water sensor had a temperature meter, we could make sure, even though it would never happen / should never happen. Let's add an assertion to the pseudocode we started above.

Instead of the boiling point (100 Celsius degrees), we will seek a more reasonable maximum of 70 Celsius degrees, which should still never be reached when thinking of trapping rainwater, at least, in our opinion. Recuerde la palabraopinión”, since it becomes important when considering the intelligence of the developer implementing the claim. (More on this below).

if (sensor_readout == nonsensical) then {
  raise_error
  fail
}else{
  assert (water_temp < 70.0){ 
    raise_assert_message 
    fail 
    exit 
  } 
  if (water_level > high_water_mark) then {
    raise_alert
  }
}

Escribimos la afirmación al revés. El código debe afirmar que la temperatura del agua es inferior a 70 grados centígrados. If that is not the case, ejecutará el bloque de código, which will generate an assertion message, and then the software will crash and close.

The assertions in the actual code are quite similar to the example above. They check whether a certain situation applies or not and, subsequently, stop (or block in a controlled way) the program / software in question.

Often, these assets are recorded in the application's log files or even directly in the screen output. Review them and / or search for a copy of the exact affirmation message on your favorite search engine often (if the error was found previously) will take you to a bug report about it.

Affirmation messages are often mistakes, even though they may simply be errors in the developer's reasoning. After all, Who says inside 1000 years, rain may not exceed 70 grados centígrados? (Hope not!)

An assertion message is the output presented by the assertion introduced by the developers in the code, In other words, the actual textual output generated by the software and as displayed on the screen or in logs. As an example, imagine this assertion message is displayed for the above program.

Assert: (water_temp < 70): (88 < 70): false

Even when it seems a bit cryptic (as are some affirmation messages), looking a little closer makes us realize that in the second part, water_temp was exchanged for 88 and that the output is false (In other words, the assertion water_temp <70 falló debido a que el agua estaba a 88 grados y, por eso, la aserción desencadenó el mensaje de aserción). Sí, puede resultar un poco confuso.

Armed with these new abilities, debugging an assertion message the next time you see one becomes a lot easier. In addition, it is possible to make it easier for you to understand exactly what was wrong when the application was stopped..

What is a Error?

Computer errors happen all the time and for a wide variety of reasons. They occur at both the developer and user level and at every step in between. As an example, a DevOps engineer may forget to include a required file, or the signer of a package may use the wrong key to sign the software, and so on.

In summary, a computer error can be set as a hindrance with the computer hardware or software. There are some examples of a bug even in the limited pseudocode above. When the sensor_readout == nonsensical the condition is met, an error message is displayed.

There are certain errors that are more common than others. As an example, using the wrong path or filename is a common mistake. Energy related problems (as an example, low battery) they are also quite common mistakes.

The errors are quite separate and different from the assertion messages, even though the assertion message itself can be seen as an error, Or better, as an undefined situation that now covers the assertion. Usually, a computer error translates quite well into “I need a human to fix this problem”.

As computers get smarter and AI progresses, expect fewer errors, even though there is plenty of room for discussion and even for arguments in that area.

What is a Shock?

A computer crash can take many forms. We are all familiar with Microsoft Windows Blue Screens, that used to occur when an application misbehaved or some core part of the machine's operating system or hardware failed.

Despite this, Most of the time, a crash is a software application that is in an undefined situation. There are many undefined possible scenarios of this type. It is possible that a computer has tried to write to an area of ​​RAM that was already in use, what upset herself or another application, or maybe you came across a scenario where you tried to divide by zero (which is impossible), or some equivalent situation.

Many operating systems will write a kernel dump file (if that's how it is configured), what enables a developer and, sometimes, to an end user with some skill, debug the issue in question.

If you want to learn more about debugging when things go wrong, including analysis of kernel dump files, you may be interested in our post Debugging with GDB: Introduction.

A crash can also be the result of an application that is in an undefined situation, which is not handled through an error (the easiest way for an app to report something wrong) or an affirmation (a deeper obstacle, originally excluded by developer as impossible but still occurs).

At the same time, note that a program compilation for testing, In other words, with debug information (including debug level assertions only) embedded in the final result binary, can fail when producing an assertion, How is the case, as an example, con MySQL. server.

Ending

In this post, we explore the concepts of affirmations, errors and crashes, as well as how they are related. We take an in-depth look at what claims within the code would look like and how this relates to a real-life example of monitoring water level and temperature with a water sensor.. The next time you come across an affirmation message, take a closer look and enjoy debugging.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.