Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
27 votes
Accepted

C# TCP server/client class

Networking You have done the classic thing that all people new to TCP do of assuming that whatever NetworkStream.Read gives you will be some meaningful chunk of ...
VisualMelon's user avatar
  • 7,581
23 votes
Accepted

Custom error-logging

Reusable methods Notice that you have several methods that essentially do the same thing. Log and both writeCustomErrorLog ...
Flater's user avatar
  • 5,710
17 votes
Accepted

A simple error messaging and logging system via macro(s) in C++

You’ve already noted that this could be done better without macros, so I won’t belabour the point. I will note, though, that your goal—“to refresh [your] skills at writing good solid macros”—makes ...
indi's user avatar
  • 16.5k
15 votes
Accepted

How much error handling is too much?

Let's start with a code review. Your style is pleasant with good naming and indentation. About the only thing I would suggest is that method RetrieveFoobar could ...
Rick Davin's user avatar
  • 6,752
15 votes
Accepted

Robust error handling mechanism in C++ (safer than std::expected)

Design review Your design description has a number of factual errors and misunderstandings in it, and more than a little questionable reasoning, all of which undermines the design of ...
indi's user avatar
  • 16.5k
14 votes
Accepted

ASP.NET REST controller with try-catch error handling

throw ex; This is a fatal mistake. It'll create a new stack-trace and you won't be able to tell where the actual exception occured. If you want to rethrow it then ...
t3chb0t's user avatar
  • 44.7k
14 votes
Accepted

Heap implementation for numeric types

Memory management You never delete[] arr;, which leaks memory. Not a good thing! There are multiple ways to fix this: Adding correct calls to ...
hoffmale's user avatar
  • 6,528
12 votes
Accepted

Decoding assembly instructions in a Game Boy disassembler

I have some ideas about how you might be able to improve your program. Avoid problems Rather than trying to deal with the problem for every instruction, one approach is avoiding it entirely. One ...
Edward's user avatar
  • 67.2k
12 votes

Dividing two numbers then handle the divide by zero exception with try/catch

If you know that you want to divide two numbers then IMHO it would make more sense to perform a pre-liminary check. In other words, rather than executing the operation "blindly" by trusting ...
Peter Csala's user avatar
  • 10.8k
11 votes
Accepted

Compiling all Exception messages into a string

Readability first I've tried to condense everything to one line, but am unsure if this is the most efficient way of approaching this problem. Your primary goal when writing code is readability and ...
t3chb0t's user avatar
  • 44.7k
11 votes
Accepted

Go function to test whether a file exists

Instead of checking with an if statement if errStat is null and then returning false: ...
Eliahu Aaron's user avatar
11 votes

C# TCP server/client class

Review This review handles readability metrics and C# conventions only and should provide insights to reach some of your goals. Goals: learn C#, improve coding style, create good to read code There ...
dfhwze's user avatar
  • 14.2k
11 votes
Accepted

Python implementation of atoi

Python already has an exception that denotes that the value you passed is inappropriate somehow. It is ValueError, which is what the built-in ...
Graipher's user avatar
  • 41.7k
11 votes

Robust program to write an array of certain data type to a binary file and read back from it (C++17)

using namespace std; Don't do using namespace std;. It can lead to name collisions and other issues. Typing out the full names (...
user673679's user avatar
  • 12.2k
10 votes
Accepted

An exception-safe wrapper for std::stoi

This wrapper effectively removes some of the available functionality from std::stoi() because its signature is ...
Null's user avatar
  • 1,463
10 votes
Accepted

Skipping over failed imports until they are needed (if ever)

There is one issue with your approach which is, in the case of multiple import failure, only the last one can be properly reported: ...
301_Moved_Permanently's user avatar
10 votes

How much error handling is too much?

If the function is central to your application then it's perfectly normal to have extensive error handling, compared to the rest of the code. In practice the amount of error handling is dictated by ...
Kate's user avatar
  • 8,138
9 votes
Accepted

Setter error checking

Input validation is a critical aspect of any reliable program. Your code is functional, but there are a few things to note. First up, the RuntimeException is not a ...
rolfl's user avatar
  • 98.1k
9 votes
Accepted

Should my Json storage handle exceptions?

This is how I see things... Throwing ArgumentException insinde a try/catch that at the same time swollows it is pointless. You ...
t3chb0t's user avatar
  • 44.7k
9 votes
Accepted

Error solution: Uncaught TypeError

Does this open up the possibility for any buggy behavior that I don't know about? It's not likely to. The if statement is fine, though it can be made cleaner: ...
CertainPerformance's user avatar
9 votes

How much error handling is too much?

Reduce your error handling to a single line. When you have any code where you are following the same basic format a lot like this to the point it makes your code too verbose for your own personal ...
Nosajimiki's user avatar
9 votes

Basic scoped timer struct design

I don't see why m_end is a member, as it's unassigned for the object's entire life, and only meaningful within the destructor. I would make it a local variable ...
Toby Speight's user avatar
  • 88.2k
9 votes
Accepted

Dividing two numbers then handle the divide by zero exception with try/catch

If you need a repetition either use a recursive call or a loop. In this situation a loop makes sense. ...
Olivier Jacot-Descombes's user avatar
9 votes

Robust error handling mechanism in C++ (safer than std::expected)

Your class does make sure the DataFunction is only called if there is actually Data stored in the variant. However, it suffers ...
G. Sliepen's user avatar
  • 69.2k
9 votes

Python Exception Monitor

It's likely to be irrelevant for most parameters, but I think that self.nb_calls += 1 belongs in the try block before calling ...
mirrorcoloured's user avatar
8 votes

Recording error messages from an exception

In C# 6 or later you can write it in a single line of code using the null conditional operator (?.) and the null coalescing operator (...
Zohar Peled's user avatar
8 votes
Accepted

Error-Handling Class and Logging for VBA

Amount of boilerplate code As it is, there are lot of boilerplate that we must provide to set up everything. At a minimum, we need the following code: ...
this's user avatar
  • 2,039
8 votes

An exception-safe wrapper for std::stoi

int _stoi(std::string str, int* p_value) { Identifiers that begins with an underscore is reserved to the implementation for use as a name in the global namespace. ...
Snowhawk's user avatar
  • 6,770
8 votes

Network helper class with retry logic on failure

Just wanted to add that you may want to consider using Polly instead of rolling your own retry mechanism - this is a library built specifically for this kind of retry mechanism (as well as many more ...
rob.earwaker's user avatar
8 votes
Accepted

Handling exceptions in Python 3

Rather than using as e then raise e you can just omit e. ...
Peilonrayz's user avatar
  • 44.5k

Only top scored, non community-wiki answers of a minimum length are eligible

Morty Proxy This is a proxified and sanitized view of the page, visit original site.