Questions tagged [error-handling]

The various techniques used for maintaining stable program state in circumstances that, if not taken care of ("handled"), could cause serious issues, including logical bugs and abrupt execution termination.

Filter by
Sorted by
Tagged with
37
votes
6answers
3k views

Resolving a link

How can I clean this up? ...
31
votes
6answers
4k views

Unbreakable average program

I'm creating a program that averages four numbers - three from a file and one from user input. Simple enough. But the catch is, the professor is going to be deliberately trying to break the program. ...
30
votes
3answers
9k views

Using default None values in Python when assigning split() to a tuple

Let's say I want to parse audio track information into two variables like this: '2/15' -> track = 2, num_tracks = 15 ...
28
votes
3answers
1k views

A Failable<T> that allows safe returning of exceptions

This was inspired by a conversation in chat, that started with the discussion of C#7.0 tuples and out parameter declarations, which led to the idea that there is no 'good1' way to return an error ...
27
votes
3answers
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 ...
24
votes
4answers
10k views

Simple Turing machine simulator

Yesterday I got a sudden urge to go from writing Python to something, well, more UNIX core-ish. I read some examples on here and decided I might as well put some of that stuff to use to test something ...
23
votes
7answers
10k views

Is wrapping exceptions good practice? [closed]

I have recently been refactoring some code in an effort to improve the exception handling, particularly to aid in improving the level of information given to developers during development. However I ...
22
votes
3answers
11k views

Returning status codes from business layer

This is what I've been doing so far in my business layer to return error messages to the user. ...
19
votes
1answer
416 views

Wanted a cat. Got lolcat

Wanna learn Rust? Ya rly! I can haz FizzBuzz? No wai! Gimme /bin/cat then. But rustc say LOL! Must handle teh err0rz! Now iz ...
18
votes
4answers
26k views

Attempt to reconnect, with timeout

I have a situation in which a program, communicating over the network, can timeout or otherwise fail to establish a connection through no fault of my application or its user. If and when this happens, ...
17
votes
3answers
11k views

Generic C++ exception catch handler macro

I have this set of legacy C++ projects with a large number of public functions. At the start, none of those publicly exposed functions had try..catch insulation ...
17
votes
2answers
6k views

Variant class with full move support

I tried to write my own variant class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from <...
16
votes
5answers
2k views

Populating a ListView with Items

I populate a ListView with Items. Each Item has data attached to its .Tag property. Over time, I have needed to handle many cases where something would be null or ...
16
votes
7answers
92k views

Euclid's Algorithm (Greatest Common Divisor)

According to Donald Knuth in "The Art Of Computer Programming", the following is how to find the greatest common divisor of two positive numbers, m and n, using Euclid's Algorithm. Divide m by n ...
16
votes
6answers
1k views

Storytelling program: Gathers stories from certain popular story websites/formats and reads them aloud

Audiobooks make my life easier when I have idle ears and a mind free to wander, but something better for my eyes to do. This program is one of my more recent efforts to allow most of the stories ...
15
votes
5answers
13k views

Is it ok to use goto in catch?

...
15
votes
5answers
114k views

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

The code below is pretty self explanatory: just copy and paste it all into a module and run it, it provides a few use cases and many explanatory comments in the text. (It works but I'm interested to ...
15
votes
2answers
4k views

Using finally with return statement or not

I was wondering if it is the proper way to always put the return statement of a function with a try-catch clause in the finally ...
15
votes
2answers
1k views

File reader/writer (text)

Following-up on this post, I wanted to be able to use my FileWriter with a syntax reminiscent of .net's using blocks, which ...
15
votes
1answer
2k views

Brainfuck-to-C compiler written in C++

This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary. Expected usage is as follows: Build ...
14
votes
7answers
3k views

Imposing a sort order on a query

I've always been told "never use goto, there's always a better way" and for the longest time I just accepted it. Lately though, I've been running into such scenarios in which I have to repeat this bit ...
14
votes
8answers
9k views

Console application for providing detailed error messages

I'm writing a console application where I need to provide detailed error messages in case anything goes wrong. As a result of this, I find myself splitting up my code into many pieces and making sure ...
14
votes
3answers
4k 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) ...
14
votes
2answers
3k views

Returning result and error status for number type conversions

Looking for review of design strategy of using a struct to return the functional result and error status. Your experience of how my design approach may succeeded ...
14
votes
2answers
49k views

Using a WCF service client and handling its exceptions

I am new to WCF and need to work with another programmer's code. I am unsure of the way the WCF service client is used here: ...
14
votes
2answers
299 views

Executing a program with a temporary directory and measuring the running time

I need a code review for best practices and code correctness of the following piece of code. run executes a program and validates in output. If the output is valid ...
14
votes
1answer
105k views

Reading data from Excel sheet with ExcelDataReader

Objective: I want to import an Excel file, and read the rows of certain columns. For this, I use ExcelDataReader. I've implemented a low-level class called ...
13
votes
3answers
3k views

Custom error-logging

I'm writing a static class to log my application errors into a text file. I am planning on using this as a library on any application I intend to develop in the future. Please let me know how I can ...
13
votes
2answers
7k views

Handling many networking exceptions in Ruby

What would be a prettier/faster way to do handling of multiple errors in Ruby? Here is the code I am working with: ...
13
votes
1answer
39k views

Error Handling - Controller's OnException and Application_Error

I'm pretty new to MVC. Below is the code that I have added to an existing MVC 5 application. The code is using log4net to log any run-time error/exception. NOTE: I could override ...
13
votes
2answers
13k views

Better option than “errno” for file IO error handling

I have the following method for opening a file: ...
12
votes
3answers
4k views

C# TCP server/client class

Goal My goal is to create a TCP server/client class that can be universally reused in various private projects. It should work stable and does not need to be super fast, but rather light-weight to ...
12
votes
4answers
48k views

Checking if a port is in use

Review this code, which should return true if a port is in use or false if the port is not in use. Clarification: "In use" ...
12
votes
1answer
1k views

C++ alternative to exceptions

I've been thinking about error handling in C++ lately. Exceptions are a great way of handling errors in most applications. However, I work in the games industry where it is commonly accepted that ...
12
votes
2answers
2k views

Productivity app for Android

I wrote a productivity app for Android. It lets you switch system settings, like Bluetooth, wife, screen brightness, volumes, ringtones, mobile data, airplane mode, etc. Unfortunately I have ...
11
votes
6answers
1k views

Retrieving multiple versions of source code for a file

I have the following code that checks for three different properties. Unfortunately each call can throw up to four exceptions that I all have to catch. Can I some how make the code more readable by ...
11
votes
4answers
2k views

Writing null-safe code to set form values

I will ask my question using the following example: HTML ...
11
votes
3answers
547 views

Exception handling, et al - How do I make this web downloader not “poor”?

I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions: Why is this error handling considered poor? How am I supposed to be doing it? ...
11
votes
4answers
549 views

Get Workbook Method(s)

I'm re-writing my Module of standard methods. These 3 are used to retrieve Workbooks as Workbook Objects. The standard I'm aiming for here is "Third-party Library/Add-in". So: Do these functions ...
11
votes
3answers
2k views

Decoding assembly instructions in a Game Boy disassembler

I am coding a game boy disassembler in C++. The program (simplified here) converts a vector of byte into an assembly instruction and print it. To do so, it iterates through the vector of bytes (char)...
11
votes
5answers
10k views

Validation that also returns error messages

My Create, Update and Delete methods should return a ...
11
votes
5answers
63k views

Reading from a serial port

I'm receiving data from a serial port in C, using Serial Programming Guide for POSIX Operating Systems as a guide. The data I receive should be always 10 bytes in length but I want to be sure that, ...
11
votes
2answers
1k views

Memoizing decorator that can retry

I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional ...
11
votes
2answers
10k views

Verifying the type of an AggregateException's inner exception in a unit test

I've got the following code inside an integration test. ...
11
votes
1answer
1k views

Simple C++ alternative to exceptions for embedded systems

I have researched ways to implement a simpler alternative for C++ exceptions. The problem I had with exceptions was the complex and not-portable stack unwinding process which makes it hard to ...
10
votes
8answers
10k views

Replace strings in a file

I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to ...
10
votes
4answers
3k views

Send email just once per day

I want to send an email just once per day. There is one button and any user can click that button. The email must not be sent twice. When the first user clicks the button, the email is sent. If ...
10
votes
3answers
5k views

Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors

I'm trying to learn exception handling in C++. I wanted to read two integers and divide them and print them. The code should throw an exception when the second integer is zero, ask the user to re-...
10
votes
3answers
2k views

Coding style of critical server's code

I was writing a server that should serve more or less a thousand clients. After writing the net part of the server code I had to stop writing because I saw that the code was chaotic and not very ...
10
votes
4answers
1k views

Skipping over failed imports until they are needed (if ever)

We have a program with many dependencies. Because the user may not want to use all of them, the program should skip over failed imports and only raise an error if absolutely necessary. e.g. if the ...

1 2 3 4 5 15