Tag

c#

Browsing

One of the concepts worth understanding when writing a custom converter for the popular Newtonsoft JSON framework is that of the JsonToken, and the role it plays in helping you understand the JSON being read.The JsonToken documentation for Newtonsoft is relatively sparse – in part because once you understand it, it’s a relatively simple concept.Effectively, when you’re attempting to deserialise a string representation of a JSON object, such as in the ReadJson method of a…

One common question that comes up when working with exceptions in C#, is whether or not you should re-throw an existing exception by specifying the exception, or just using the throw keyword where an error occurs.In most cases, it’s best to rethrow the existing exception, such as below:try { var networkResponse = await someNetworkService.GetAllPosts();}catch (Exception ex){ Log.Warning(“An exception occurred”, ex); //Now lets rethrow this same exception throw;}By doing so, you ensure that the original stack…