31 votes
Accepted

A Failable<T> that allows safe returning of exceptions

First: congratulations, you have rediscovered the error monad. https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Error.html Second: as noted in the comments, C# already has the ...
Eric Lippert's user avatar
  • 14.7k
26 votes

Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors

Exceptions are for exceptional cases I'm trying to learn exception handling in C++. This is a very bad example to learn exceptions. They are meant for situations where you cannot know that there ...
Zeta's user avatar
  • 19.2k
26 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,421
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,542
19 votes
Accepted

Python exception handler to recommend package

An ImportError instance doesn't have a replace method. You can use e.name instead of messy ...
janos's user avatar
  • 111k
16 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
  • 10.2k
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,257
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.2k
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,458
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
  • 65.3k
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
  • 8,520
11 votes

Python exception handler to recommend package

First of all, this code doesn't work. e is an ImportError instance, not a string, and so it doesn't have a ...
jwodder's user avatar
  • 302
11 votes
Accepted

Are these try/catch blocks cluttering the code?

Your convert function should be pure. convert should be doing one thing and one thing only, and that is to convert the given ...
smac89's user avatar
  • 1,467
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
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
  • 40.8k
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
  • 11.6k
10 votes

Get Workbook Method(s)

I will not mention again that I find the outdenting of Dim statements hurt readability. Instead I'll focus on this part: ...
Mathieu Guindon's user avatar
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,433
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

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 ...
dfhwze's user avatar
  • 13.9k
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
  • 6,327
9 votes
Accepted

Verifying user accounts on SMTP servers

What you really want is a robust argument parsing. This calls for argparse: ...
Graipher's user avatar
  • 40.8k
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
  • 97.3k
9 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.2k
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
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
8 votes

Get Workbook Method(s)

Optional ByVal strFilePath As Variant Why are you allowing this to be a Variant? Why not simply require a string type (?). This eliminates the already awkward <...
enderland's user avatar
  • 1,736
8 votes
Accepted

Many nested session verification conditions

This is indeed quite messy. It's really hard to see which else ends which if. Just invert the if and return early: ...
tim's user avatar
  • 25.1k

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