Should my Json storage handle exceptions?Handling parsing failure in Scala without exceptionsProper usage of “using” statement in base64 encode methodHandling an invalid SQL query exceptionSecuring User Credentials in CookiesQuerying Facebook for details of a user's OAuth tokenLower level exception handling during enumerationImplementation of a Location object, to be used in building a text-based adventure gameSimple Product Inventory software using C# and OOPClass handler systemGenerate URLs, Download, extract and add files

A Cunning Riley Riddle

Exception propagation

Why do Thanos' punches not kill Captain America or at least cause vital wounds?

When quoting someone, is it proper to change "gotta" to "got to" without modifying the rest of the quote?

Extending Kan fibrations, without using minimal fibrations

Is ‘despite that’ right?

Why does increasing the sampling rate make implementing an anti-aliasing filter easier?

How to make a language evolve quickly?

How can I avoid subordinates and coworkers leaving work until the last minute, then having no time for revisions?

Removing all characters except digits from clipboard

How to handle DM constantly stealing everything from sleeping characters?

Is it a Munchausen Number?

Why do the Avengers care about returning these items in Endgame?

How to get the IP of a user who executed a command?

Windows OS quantum vs. SQL OS Quantum

Renting a house to a graduate student in my department

Is this state of Earth possible, after humans left for a million years?

Cryptography and elliptic curves

Why use steam instead of just hot air?

Is there an application which does HTTP PUT?

Can the president of the United States be guilty of insider trading?

Why should password hash verification be time consistent?

How is CoreiX like Corei5, i7 is related to Haswell, Ivy Bridge?

Was Mohammed the most popular first name for boys born in Berlin in 2018?



Should my Json storage handle exceptions?


Handling parsing failure in Scala without exceptionsProper usage of “using” statement in base64 encode methodHandling an invalid SQL query exceptionSecuring User Credentials in CookiesQuerying Facebook for details of a user's OAuth tokenLower level exception handling during enumerationImplementation of a Location object, to be used in building a text-based adventure gameSimple Product Inventory software using C# and OOPClass handler systemGenerate URLs, Download, extract and add files






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4












$begingroup$


I made a class to conviniently serialize/deserialize data. Now I'm stuck with the following question. Should I handle exceptions (use try-catch) inside JsonStorage or inside ConfigManager and other classes that might use JsonStorage in the future?



public class JsonStorage : IDataStorage

private readonly IFileSystem fileSystem;
private readonly ILogger logger;

public JsonStorage(IFileSystem fileSystem, ILogger logger)

this.fileSystem = fileSystem;
this.logger = logger;


public T RestoreObject<T>(string path)

T result = default;

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

string json = fileSystem.File.ReadAllText($"path.json");
result = JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

logger.Log($"Object can't be restored. ex.Message");


return result;


public void StoreObject(object obj, string path)

string file = $"path.json";

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

fileSystem.Directory.CreateDirectory(fileSystem.Path.GetDirectoryName(file));
var json = JsonConvert.SerializeObject(obj, Formatting.Indented);
fileSystem.File.WriteAllText(file, json);

catch (Exception ex)

logger.Log($"Object can't be stored. ex.Message");





public static class ConfigManager

private static readonly string configPath = @"SomePathConfig";

public static BotConfig LoadConfig()

return Unity.Resolve<IDataStorage>().RestoreObject<BotConfig>(configPath);


public static void SaveConfig(BotConfig config)

Unity.Resolve<IDataStorage>().StoreObject(config, configPath);




ConfigManager - example class that holds a path to Config.json and loads/saves it (using JsonStorage internaly).



For now I'm catching exceptions inside JsonStorage and using a logger instance to print exception messages to the console.
I don't know if there's a downside to that. Should JsonStorage have its own logger? Should it throw an exception (just like ReadAllText/WriteAllText) when something goes wrong with path/files?
Or maybe there is a good practice and some better ways to handle exceptions (in my particular case)?










share|improve this question











$endgroup$







  • 2




    $begingroup$
    "Hint: If your title contains a question, it is likely a bad title."
    $endgroup$
    – Georgy
    Apr 30 at 20:34


















4












$begingroup$


I made a class to conviniently serialize/deserialize data. Now I'm stuck with the following question. Should I handle exceptions (use try-catch) inside JsonStorage or inside ConfigManager and other classes that might use JsonStorage in the future?



public class JsonStorage : IDataStorage

private readonly IFileSystem fileSystem;
private readonly ILogger logger;

public JsonStorage(IFileSystem fileSystem, ILogger logger)

this.fileSystem = fileSystem;
this.logger = logger;


public T RestoreObject<T>(string path)

T result = default;

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

string json = fileSystem.File.ReadAllText($"path.json");
result = JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

logger.Log($"Object can't be restored. ex.Message");


return result;


public void StoreObject(object obj, string path)

string file = $"path.json";

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

fileSystem.Directory.CreateDirectory(fileSystem.Path.GetDirectoryName(file));
var json = JsonConvert.SerializeObject(obj, Formatting.Indented);
fileSystem.File.WriteAllText(file, json);

catch (Exception ex)

logger.Log($"Object can't be stored. ex.Message");





public static class ConfigManager

private static readonly string configPath = @"SomePathConfig";

public static BotConfig LoadConfig()

return Unity.Resolve<IDataStorage>().RestoreObject<BotConfig>(configPath);


public static void SaveConfig(BotConfig config)

Unity.Resolve<IDataStorage>().StoreObject(config, configPath);




ConfigManager - example class that holds a path to Config.json and loads/saves it (using JsonStorage internaly).



For now I'm catching exceptions inside JsonStorage and using a logger instance to print exception messages to the console.
I don't know if there's a downside to that. Should JsonStorage have its own logger? Should it throw an exception (just like ReadAllText/WriteAllText) when something goes wrong with path/files?
Or maybe there is a good practice and some better ways to handle exceptions (in my particular case)?










share|improve this question











$endgroup$







  • 2




    $begingroup$
    "Hint: If your title contains a question, it is likely a bad title."
    $endgroup$
    – Georgy
    Apr 30 at 20:34














4












4








4





$begingroup$


I made a class to conviniently serialize/deserialize data. Now I'm stuck with the following question. Should I handle exceptions (use try-catch) inside JsonStorage or inside ConfigManager and other classes that might use JsonStorage in the future?



public class JsonStorage : IDataStorage

private readonly IFileSystem fileSystem;
private readonly ILogger logger;

public JsonStorage(IFileSystem fileSystem, ILogger logger)

this.fileSystem = fileSystem;
this.logger = logger;


public T RestoreObject<T>(string path)

T result = default;

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

string json = fileSystem.File.ReadAllText($"path.json");
result = JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

logger.Log($"Object can't be restored. ex.Message");


return result;


public void StoreObject(object obj, string path)

string file = $"path.json";

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

fileSystem.Directory.CreateDirectory(fileSystem.Path.GetDirectoryName(file));
var json = JsonConvert.SerializeObject(obj, Formatting.Indented);
fileSystem.File.WriteAllText(file, json);

catch (Exception ex)

logger.Log($"Object can't be stored. ex.Message");





public static class ConfigManager

private static readonly string configPath = @"SomePathConfig";

public static BotConfig LoadConfig()

return Unity.Resolve<IDataStorage>().RestoreObject<BotConfig>(configPath);


public static void SaveConfig(BotConfig config)

Unity.Resolve<IDataStorage>().StoreObject(config, configPath);




ConfigManager - example class that holds a path to Config.json and loads/saves it (using JsonStorage internaly).



For now I'm catching exceptions inside JsonStorage and using a logger instance to print exception messages to the console.
I don't know if there's a downside to that. Should JsonStorage have its own logger? Should it throw an exception (just like ReadAllText/WriteAllText) when something goes wrong with path/files?
Or maybe there is a good practice and some better ways to handle exceptions (in my particular case)?










share|improve this question











$endgroup$




I made a class to conviniently serialize/deserialize data. Now I'm stuck with the following question. Should I handle exceptions (use try-catch) inside JsonStorage or inside ConfigManager and other classes that might use JsonStorage in the future?



public class JsonStorage : IDataStorage

private readonly IFileSystem fileSystem;
private readonly ILogger logger;

public JsonStorage(IFileSystem fileSystem, ILogger logger)

this.fileSystem = fileSystem;
this.logger = logger;


public T RestoreObject<T>(string path)

T result = default;

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

string json = fileSystem.File.ReadAllText($"path.json");
result = JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

logger.Log($"Object can't be restored. ex.Message");


return result;


public void StoreObject(object obj, string path)

string file = $"path.json";

try

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException("Invalid path.", nameof(path));

fileSystem.Directory.CreateDirectory(fileSystem.Path.GetDirectoryName(file));
var json = JsonConvert.SerializeObject(obj, Formatting.Indented);
fileSystem.File.WriteAllText(file, json);

catch (Exception ex)

logger.Log($"Object can't be stored. ex.Message");





public static class ConfigManager

private static readonly string configPath = @"SomePathConfig";

public static BotConfig LoadConfig()

return Unity.Resolve<IDataStorage>().RestoreObject<BotConfig>(configPath);


public static void SaveConfig(BotConfig config)

Unity.Resolve<IDataStorage>().StoreObject(config, configPath);




ConfigManager - example class that holds a path to Config.json and loads/saves it (using JsonStorage internaly).



For now I'm catching exceptions inside JsonStorage and using a logger instance to print exception messages to the console.
I don't know if there's a downside to that. Should JsonStorage have its own logger? Should it throw an exception (just like ReadAllText/WriteAllText) when something goes wrong with path/files?
Or maybe there is a good practice and some better ways to handle exceptions (in my particular case)?







c# json error-handling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 30 at 14:46







Glitch

















asked Apr 30 at 12:08









GlitchGlitch

978




978







  • 2




    $begingroup$
    "Hint: If your title contains a question, it is likely a bad title."
    $endgroup$
    – Georgy
    Apr 30 at 20:34













  • 2




    $begingroup$
    "Hint: If your title contains a question, it is likely a bad title."
    $endgroup$
    – Georgy
    Apr 30 at 20:34








2




2




$begingroup$
"Hint: If your title contains a question, it is likely a bad title."
$endgroup$
– Georgy
Apr 30 at 20:34





$begingroup$
"Hint: If your title contains a question, it is likely a bad title."
$endgroup$
– Georgy
Apr 30 at 20:34











1 Answer
1






active

oldest

votes


















8












$begingroup$

This is how I see things...



  • Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You use ArgumentException to inform the user that he called your API in a wrong way. This is not something one should hangle because he won't see it until he looks at the logs. The app should crash in this case.

  • The message of the ArgumentException is too generic. When it happens, the user already knows something is wrong. Tell him how to fix that by giving him a hint what the correct path should be and what path he actually used.

  • The way you are handling exceptions that might be thrown by the json-serializer is unexpected (non-standard) because the user will wonder why he got a null without noticing anything. public library APIs should always throw unless they are called TryDoSomething and return a bool.

  • Yet another flaw of this pattern is that it doesn't help anyone to find the source of the exception. You neither add the filename to it nor the object that it tried to de/serialize. This is very important piece of information and should be included.

So, what you can/should do instead is to throw a new exception that adds more information about what happened e.g.:



public T RestoreObject<T>(string path)

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException($"Invalid path: 'path'. It must by fully qualified.", nameof(path));

try

string json = fileSystem.File.ReadAllText($"path.json");
return JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

throw new JsonStorageException($"Could not restore object 'typeof(T).Name' from 'path'.", ex);




You'll be happy to see the type and file name when something goes wrong.






share|improve this answer











$endgroup$












  • $begingroup$
    Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
    $endgroup$
    – Glitch
    Apr 30 at 16:04











  • $begingroup$
    @Glitch you pass the original exception as inner-exception. See the last parameter.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:05










  • $begingroup$
    oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
    $endgroup$
    – Glitch
    Apr 30 at 16:07











  • $begingroup$
    @Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:09












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f219425%2fshould-my-json-storage-handle-exceptions%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8












$begingroup$

This is how I see things...



  • Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You use ArgumentException to inform the user that he called your API in a wrong way. This is not something one should hangle because he won't see it until he looks at the logs. The app should crash in this case.

  • The message of the ArgumentException is too generic. When it happens, the user already knows something is wrong. Tell him how to fix that by giving him a hint what the correct path should be and what path he actually used.

  • The way you are handling exceptions that might be thrown by the json-serializer is unexpected (non-standard) because the user will wonder why he got a null without noticing anything. public library APIs should always throw unless they are called TryDoSomething and return a bool.

  • Yet another flaw of this pattern is that it doesn't help anyone to find the source of the exception. You neither add the filename to it nor the object that it tried to de/serialize. This is very important piece of information and should be included.

So, what you can/should do instead is to throw a new exception that adds more information about what happened e.g.:



public T RestoreObject<T>(string path)

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException($"Invalid path: 'path'. It must by fully qualified.", nameof(path));

try

string json = fileSystem.File.ReadAllText($"path.json");
return JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

throw new JsonStorageException($"Could not restore object 'typeof(T).Name' from 'path'.", ex);




You'll be happy to see the type and file name when something goes wrong.






share|improve this answer











$endgroup$












  • $begingroup$
    Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
    $endgroup$
    – Glitch
    Apr 30 at 16:04











  • $begingroup$
    @Glitch you pass the original exception as inner-exception. See the last parameter.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:05










  • $begingroup$
    oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
    $endgroup$
    – Glitch
    Apr 30 at 16:07











  • $begingroup$
    @Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:09
















8












$begingroup$

This is how I see things...



  • Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You use ArgumentException to inform the user that he called your API in a wrong way. This is not something one should hangle because he won't see it until he looks at the logs. The app should crash in this case.

  • The message of the ArgumentException is too generic. When it happens, the user already knows something is wrong. Tell him how to fix that by giving him a hint what the correct path should be and what path he actually used.

  • The way you are handling exceptions that might be thrown by the json-serializer is unexpected (non-standard) because the user will wonder why he got a null without noticing anything. public library APIs should always throw unless they are called TryDoSomething and return a bool.

  • Yet another flaw of this pattern is that it doesn't help anyone to find the source of the exception. You neither add the filename to it nor the object that it tried to de/serialize. This is very important piece of information and should be included.

So, what you can/should do instead is to throw a new exception that adds more information about what happened e.g.:



public T RestoreObject<T>(string path)

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException($"Invalid path: 'path'. It must by fully qualified.", nameof(path));

try

string json = fileSystem.File.ReadAllText($"path.json");
return JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

throw new JsonStorageException($"Could not restore object 'typeof(T).Name' from 'path'.", ex);




You'll be happy to see the type and file name when something goes wrong.






share|improve this answer











$endgroup$












  • $begingroup$
    Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
    $endgroup$
    – Glitch
    Apr 30 at 16:04











  • $begingroup$
    @Glitch you pass the original exception as inner-exception. See the last parameter.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:05










  • $begingroup$
    oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
    $endgroup$
    – Glitch
    Apr 30 at 16:07











  • $begingroup$
    @Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:09














8












8








8





$begingroup$

This is how I see things...



  • Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You use ArgumentException to inform the user that he called your API in a wrong way. This is not something one should hangle because he won't see it until he looks at the logs. The app should crash in this case.

  • The message of the ArgumentException is too generic. When it happens, the user already knows something is wrong. Tell him how to fix that by giving him a hint what the correct path should be and what path he actually used.

  • The way you are handling exceptions that might be thrown by the json-serializer is unexpected (non-standard) because the user will wonder why he got a null without noticing anything. public library APIs should always throw unless they are called TryDoSomething and return a bool.

  • Yet another flaw of this pattern is that it doesn't help anyone to find the source of the exception. You neither add the filename to it nor the object that it tried to de/serialize. This is very important piece of information and should be included.

So, what you can/should do instead is to throw a new exception that adds more information about what happened e.g.:



public T RestoreObject<T>(string path)

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException($"Invalid path: 'path'. It must by fully qualified.", nameof(path));

try

string json = fileSystem.File.ReadAllText($"path.json");
return JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

throw new JsonStorageException($"Could not restore object 'typeof(T).Name' from 'path'.", ex);




You'll be happy to see the type and file name when something goes wrong.






share|improve this answer











$endgroup$



This is how I see things...



  • Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You use ArgumentException to inform the user that he called your API in a wrong way. This is not something one should hangle because he won't see it until he looks at the logs. The app should crash in this case.

  • The message of the ArgumentException is too generic. When it happens, the user already knows something is wrong. Tell him how to fix that by giving him a hint what the correct path should be and what path he actually used.

  • The way you are handling exceptions that might be thrown by the json-serializer is unexpected (non-standard) because the user will wonder why he got a null without noticing anything. public library APIs should always throw unless they are called TryDoSomething and return a bool.

  • Yet another flaw of this pattern is that it doesn't help anyone to find the source of the exception. You neither add the filename to it nor the object that it tried to de/serialize. This is very important piece of information and should be included.

So, what you can/should do instead is to throw a new exception that adds more information about what happened e.g.:



public T RestoreObject<T>(string path)

if (!fileSystem.Path.IsPathFullyQualified(path))
throw new ArgumentException($"Invalid path: 'path'. It must by fully qualified.", nameof(path));

try

string json = fileSystem.File.ReadAllText($"path.json");
return JsonConvert.DeserializeObject<T>(json);

catch (Exception ex)

throw new JsonStorageException($"Could not restore object 'typeof(T).Name' from 'path'.", ex);




You'll be happy to see the type and file name when something goes wrong.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 30 at 15:32

























answered Apr 30 at 15:21









t3chb0tt3chb0t

35.7k755127




35.7k755127











  • $begingroup$
    Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
    $endgroup$
    – Glitch
    Apr 30 at 16:04











  • $begingroup$
    @Glitch you pass the original exception as inner-exception. See the last parameter.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:05










  • $begingroup$
    oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
    $endgroup$
    – Glitch
    Apr 30 at 16:07











  • $begingroup$
    @Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:09

















  • $begingroup$
    Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
    $endgroup$
    – Glitch
    Apr 30 at 16:04











  • $begingroup$
    @Glitch you pass the original exception as inner-exception. See the last parameter.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:05










  • $begingroup$
    oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
    $endgroup$
    – Glitch
    Apr 30 at 16:07











  • $begingroup$
    @Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
    $endgroup$
    – t3chb0t
    Apr 30 at 16:09
















$begingroup$
Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
$endgroup$
– Glitch
Apr 30 at 16:04





$begingroup$
Thanks for good tips. But what if ReadAllText throws some IO exception? In your code it will be re-thrown as JsonStorageException and it also doesn't provide details about what went wrong there...
$endgroup$
– Glitch
Apr 30 at 16:04













$begingroup$
@Glitch you pass the original exception as inner-exception. See the last parameter.
$endgroup$
– t3chb0t
Apr 30 at 16:05




$begingroup$
@Glitch you pass the original exception as inner-exception. See the last parameter.
$endgroup$
– t3chb0t
Apr 30 at 16:05












$begingroup$
oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
$endgroup$
– Glitch
Apr 30 at 16:07





$begingroup$
oh, didn't notice that. So you're also saying that I shouldn't have logger instance in my storages, and instead should handle thrown exceptions higher up the stack call?
$endgroup$
– Glitch
Apr 30 at 16:07













$begingroup$
@Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
$endgroup$
– t3chb0t
Apr 30 at 16:09





$begingroup$
@Glitch exactly, otherwise you have to check the result against null and break the execution there by doing something else. It's easier to use an exception for this especially that you already have one and it doesn't cost anything.
$endgroup$
– t3chb0t
Apr 30 at 16:09


















draft saved

draft discarded
















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f219425%2fshould-my-json-storage-handle-exceptions%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos