Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
35 votes

Returning status codes from business layer

Status codes have long gone the way of the Dodo --- made extinct by exceptions, actually. The problem with a status code is that it can be ignored. An exception cannot. Consider these two examples. ...
user avatar
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 ...
user avatar
  • 14.6k
27 votes
Accepted

Try catch statement in VBA using the standard VBA error handling statements

The problem is that runtime errors in VBA are not exceptions, and error-handling in VBA has very little in common with exception handling. RememberErrLine = Erl() ...
user avatar
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 ...
user avatar
  • 18.8k
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 ...
user avatar
  • 7,086
23 votes
Accepted

Wanted a cat. Got lolcat

C would have allowed you to just ignore errors and pretend everything was good. A naïve cat would be very short, but rather unreliable also. A well‐written ...
user avatar
23 votes
Accepted

Custom error-logging

Reusable methods Notice that you have several methods that essentially do the same thing. Log and both writeCustomErrorLog ...
user avatar
  • 5,397
19 votes
Accepted

Is wrapping exceptions good practice?

There is little reason to do this. If you include the stacktrace in your logs you already know where the problem exists; the only thing you'd miss is the input which you might know from different ...
user avatar
19 votes

Imposing a sort order on a query

I'm not a member of the “goto is evil and must not be used under any circumstances” camp. Especially in performance-critical low-level routines, it can be useful ...
user avatar
  • 4,230
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 ...
user avatar
  • 107k
18 votes
Accepted

Populating a ListView with Items

Yeah, sure, I could just get rid of the if's and else's and replace ((Item)list...) with Item item = list... and wrap it all in a single Try{}Catch{}, but I really do hate using Try{}Catch{} unless ...
user avatar
  • 49.9k
18 votes
Accepted

Imposing a sort order on a query

You could use goto, but you can also just define a function, as the label returns a value anyways. For example, your label ...
user avatar
15 votes

Unbreakable average program

The program cannot be made totally unbreakable. ...
user avatar
  • 481
14 votes

Coding style of critical server's code

There are quite a few points of improvement in this code. Networking is not my speciality, but I can give you several suggestions on code improvement. First, a quick word on naming: Type names in <...
user avatar
  • 17k
14 votes

Is wrapping exceptions good practice?

It depends on how you wish to present the error state to your end user. A rule of thumb: Always log the original exception (which is lower-level and very often quite technical and would scare ...
user avatar
  • 241
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 ...
user avatar
  • 6,418
14 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 ...
user avatar
  • 8,241
14 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 ...
user avatar
  • 5,532
13 votes
Accepted

Extending the VBA Extensibility Library

The only coupling I can see with MSAccess-specific vba is in your exampleCall (why is it Private anyway?): ...
user avatar
13 votes
Accepted

Coding style of critical server's code

There's lots of place for improvement. ...
user avatar
  • 3,577
13 votes

C# PasswordService class

You have asked a lot of questions and omitted the most important question. Is the security system I have developed secure against attacks? Absolutely it is not. There is an enormous security problem ...
user avatar
  • 14.6k
13 votes
Accepted

Returning result and error status for number type conversions

I don't like the idea of using an all-in-one struct. You will have to do more maintenance: every time you create a function that returns different values, you have to create a new struct. Further, I ...
user avatar
  • 2,641
13 votes

Unbreakable average program

...
user avatar
  • 19.1k
13 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 ...
user avatar
  • 43.8k
12 votes
Accepted

Async and error-handling

I need to delete a file when an error occurs during loading it. In other words: Happy path: Load a file Move on Unhappy path: Load a file, exception is thrown Delete the file Move on Exceptional ...
user avatar
12 votes
Accepted

File reader/writer (text)

Error Handling Your error handlers look much cleaner (and ultimately safer) than before. I also like your GetErrorSoure() routine and the "CleanExit:" name of the labels. Very concise. (<-Read as, ...
user avatar
  • 30.7k
12 votes

Console application for providing detailed error messages

Make a function that writes an error message (String) to the console, then exits with failure error code. But I'm not sure whether this would mess up your returns and overall control flow. Other than ...
user avatar
  • 22.2k
12 votes

Error Handling - Controller's OnException and Application_Error

The OnException() methods does 2 things. It logs the exception It creates an return value So let us refactor these two points to two separate methods. <...
user avatar
  • 49.9k
12 votes

Writing null-safe code to set form values

(document.getElementById(arr[i].id) || 0).value = arr[i].value; In this code there is a pointless assignment when the element is not found. In this case, the 0 ...
user avatar
  • 107k

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