Posts

Showing posts with the label Exception

Rubber Duck Debugging

Image
  The Origin of Rubber Duck Debugging The concept of Rubber Duck Debugging is rooted in the idea that explaining a problem or code issue to someone else can lead to a deeper understanding and, often, a solution. The story goes that a programmer would carry around a rubber duck and, when faced with a problem, would explain the code or issue to the duck. In the process of articulating the problem, the programmer would often realize the solution without any input from the duck. This practice gained popularity as a form of solo brainstorming and debugging, and it has since become a humorous yet widely recognized method in the software development community. How Rubber Duck Debugging Works The process of Rubber Duck Debugging is simple but surprisingly effective: Grab a Rubber Duck: Obtain a rubber duck or any inanimate object. The choice of the object is not critical; your ability to articulate the problem to it matters. Place the Duck on Your Desk: Set the rubbe...

How to serialise a Exception using JsonSerializer.Serialize in C#

Image
Serialising Exception Data to JSON in C# Introduction: In software development, handling exceptions is a crucial part of writing robust applications. When exceptions occur, developers often need to log and report them for debugging and monitoring purposes. One way to achieve this is by serialising exception data to JSON, allowing you to easily store and analyse error information. In this blog post, we will explore how to serialise exception data to JSON using the JsonSerializer.Serialize method in C#. We'll use a custom class, ExceptionData , to encapsulate exception information. Creating the ExceptionData Class: To get started, we need to create a custom class called ExceptionData . This class will capture various properties of an exception, such as message, source, stack trace, type name, and optionally inner exceptions. Here's the ExceptionData class: public class ExceptionData { public ExceptionData(Exception exception, bool includeInnerException = tru...