Skip to main content

All Questions

2 votes
3 answers
693 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 ...
David Gard's user avatar
3 votes
2 answers
370 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 ...
user avatar
2 votes
1 answer
717 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 ...
user3755946's user avatar
5 votes
1 answer
151 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. ...
Jack Tyler's user avatar
3 votes
1 answer
410 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 ...
npengra317's user avatar
6 votes
1 answer
79 views

Return true from enumerable that calls function unless that function ever returns false

Is there a tighter way to write this code? ...
user875234's user avatar
5 votes
3 answers
85 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 ...
Julien__'s user avatar
  • 339
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: ...
XoXo's user avatar
  • 185
2 votes
2 answers
633 views

Dict lookup with type conversion and fallback

Given the following working code: ...
Pyderman's user avatar
  • 215
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: ...
Paweł Adamski's user avatar
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 ...
ontk's user avatar
  • 121
6 votes
1 answer
124 views

Avoiding code repetition while handling exceptions

For my application, I need to use two slightly different algorithms for persisting an entity: ...
vikingr's user avatar
  • 61
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. ...
wannik's user avatar
  • 139
2 votes
1 answer
88 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, ...
Loom's user avatar
  • 555
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 ...
zadane's user avatar
  • 337

15 30 50 per page