Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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 ...
David Gard's user avatar
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 ...
user avatar
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 ...
user3755946's user avatar
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. ...
Jack Tyler's user avatar
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 ...
npengra317's user avatar
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? ...
user875234's user avatar
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 ...
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
635 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
125 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
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, ...
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
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 ...
cafe_'s user avatar
  • 465
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: ...
Novak's user avatar
  • 215
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) ...
Raj's user avatar
  • 320
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 ...
Win's user avatar
  • 183