All Questions
Tagged with error-handling comparative-review
19 questions
2
votes
3
answers
709
views
Capture multiple errors before raising an exception
I have a scenario where I need to store values from some environment variables (names of which I cannot control). My first run at this was pretty basic, however this is not usable as an exception ...
3
votes
2
answers
377
views
Retry read/write until all bytes are transferred or error occurs
Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
2
votes
1
answer
732
views
Go functions to create a directory if it doesn't exist
Which of the 2 solutions is written better? Personally I prefer the one line method but it does make it slightly more difficult to debug. Is perhaps doing it the long way first then refactoring to ...
5
votes
1
answer
154
views
Detecting the presence of multiple URL segments
I have two versions of a function that performs the same task, however I'm not sure which one to use. Speed is something to take into consideration, but I also want to know what the best practice is. ...
3
votes
1
answer
413
views
Given a list of words, remove the shorter word of every pair
This is not a "please do my homework" question. I solved a problem two ways and would like to know which solution is better; better being defined by better readability, lower complexity and lower ...
6
votes
1
answer
80
views
Return true from enumerable that calls function unless that function ever returns false
Is there a tighter way to write this code?
...
5
votes
3
answers
86
views
Four versions of a database-creation function with different error handling
I'm starting a new, small C project and would like to have the safest, cleanest and shortest error handling code possible.
Here is a comparison of different ways to handle errors in the same C ...
2
votes
4
answers
1k
views
Throwing exceptions if there is not exactly one box retrieved
(Note: this is originally posted as this SO question )
I'm trying to refactor the error logging and exception throwing into a method.
Original code:
...
2
votes
2
answers
635
views
Dict lookup with type conversion and fallback
Given the following working code:
...
6
votes
1
answer
49
views
Fetching lists and finding one with the right name, with fallback on error or no match
I have a simple function:
...
2
votes
2
answers
73
views
Controller method to validate and save
I have built RESTful web services. The services endpoints have a similar logic:
If the input validation succeeds, do a database operation and return the result.
If the db operation fails, return the ...
6
votes
1
answer
125
views
Avoiding code repetition while handling exceptions
For my application, I need to use two slightly different algorithms for persisting an entity:
...
2
votes
2
answers
1k
views
Root-finding by iterated bisection
Both of the following code give the same result. But I'm not sure where should I put the raise statement.
...
2
votes
1
answer
89
views
Two error-reporting conventions for a command-parser
I need to implement some function and I would like to report about a fail made inside a function. If function doesn't fail I need to get a some result (for example, ...
6
votes
4
answers
2k
views
Checking errors from a series of function calls
I have to work with C-style functions which return ERROR_SUCCESS when successful or an error code when not. I want my code to be nice and neat and easy to read but ...
30
votes
3
answers
2k
views
Java method - levels of abstraction
In his Clean Code book, Robert C. Martin states that functions should do only one thing and one should not mix different levels of abstraction. So I started wondering whether the code below meets ...
6
votes
3
answers
150
views
Error handling for function calls to parse a GIF file
I'm debating which version would be more suitable in parameters of code length, readability and maintenance. This is a portion of a set of functions which together parse a Gif file.
Version 1:
...
14
votes
3
answers
6k
views
Unit tests for testing error codes
Both unit tests pass and they both test the same thing. The production code uses the right error codes.
System Under Test (SUT)
...
8
votes
6
answers
14k
views
Place try/catch in business logic or user interface
I found the following two types of exception-handling in Business Logic Layer.
ASP.NET 3.5 Enterprise Application Development uses a similar method like the first one (I read it few years ago).
I ...