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 ...
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 ...
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 ...
23
votes
Accepted
Custom error-logging
Reusable methods
Notice that you have several methods that essentially do the same thing. Log and both writeCustomErrorLog ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 (...
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:
...
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
...
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:
...
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
...
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 ...
9
votes
Accepted
Verifying user accounts on SMTP servers
What you really want is a robust argument parsing. This calls for argparse:
...
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 ...
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 ...
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:
...
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 ...
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 ...
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.
...
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 <...
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:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
error-handling × 819c# × 163
java × 156
python × 104
c++ × 77
beginner × 57
php × 51
javascript × 50
exception × 45
c × 43
python-3.x × 37
vba × 34
http × 30
logging × 28
file × 26
object-oriented × 25
excel × 25
performance × 23
node.js × 21
validation × 20
asynchronous × 20
.net × 19
io × 19
ruby × 18
comparative-review × 18