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
14
votes
2answers
50k 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: ...
5
votes
2answers
2k views

Splitting a string of random length

I am currently using this code, but I am pretty sure there is a better way of doing it: ...
5
votes
1answer
3k views

Try/catch block in PDO wrapper

I have written a PDO wrapper and a class file like a model. It's looking good so far, but I'm just confuseed on where I should put the try/...
7
votes
1answer
435 views

Class representing a text file

I'm trying to write a simple class to represent a text file - which one would think should be quite easy. I don't intend to add all bells and whistles to fully represent a text file just enough to be ...
8
votes
2answers
1k views

Coding style and best practice regarding exception-handling

I need comments on my JPA code. Am I doing it correctly? I need some advice on best practices in Java. I have this method below: ...
11
votes
3answers
548 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? ...
7
votes
2answers
7k views

Handling parsing failure in Scala without exceptions

I have a Scala (Play!) application that must get and parse some data in JSON from an external service. I want to be able to gently handle failure in the response format, but it is becoming messy. What ...
6
votes
1answer
6k views

Node.js callback error pattern

The errors are passed through every callback, but in fact, it might be better to throw an error at higher levels. For example, look at the mongodb.js database function. It passes through an error in ...
5
votes
2answers
2k views

Error handling for parsing a date

Is this return style acceptable? Would the code be more readable if I assigned the MonthDay.parse() return value to a variable and returned that variable on the ...
32
votes
3answers
10k 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 ...
1
vote
1answer
364 views

Perl CGI script to respond to erroneous Base64 image requests

I often get lines like this in my Apache error log: File does not exist: /path/to/www/data:image/gif;base64,R0lGODlhBgAGAIAOAP/yH5BAEACAEALAAAAAAGGAYAAAIJhB0Xi5vOoFwFADs= Obviously, this is due to ...
6
votes
3answers
3k views

A safer way to cut a string

I want to get just the first line of a big string. Currently, here's how I do it: ...
5
votes
3answers
443 views

Allowing “plugin” programmers to subscribe to messages

I am having difficulty deciding how to implement an exception handling strategy. I am using an observer pattern to allow "plugin" programmers to subscribe to ...
7
votes
4answers
443 views

Storing .h files in SQLite using SQLJet

I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards. In ...
2
votes
1answer
358 views

Suggestions for improving error handling [closed]

I am interested in finding out what is the correct way of implementing error handling for this situation in C#. The system tries to do an operation. If the operation succeeded (returns a non-error ...
2
votes
2answers
288 views

Throwing the Exception But Using the Finally Block

Does this piece of code make sense? The idea is to throw any exceptions that may occur but always run the finally block to close the streams. ...
8
votes
3answers
3k views

Catching multiple types of exceptions when writing JSON

I have a class which throws a lot of exceptions: ...
3
votes
2answers
236 views

Add events dispatching for ActionScript framework Robotlegs

I have the following function in a Service class ...
10
votes
3answers
7k views

Encapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?

In an effort to reduce code duplication, I often use and have used this style to capture handling of exceptions on a boundary of an application: Given the following extension methods: ...
1
vote
3answers
156 views

I think I'm not using Try Except properly in this Python code [closed]

Please offer some advice for this code. It all works, but I know that its messy and I don't think the Exception catching is doing what I want it to. Thanks in advance for any and all advice... <...
1
vote
3answers
262 views

Fail-safe remote API operations for managing customers and billing

I'm working with two remote APIs: one which manages customers and the other (a Paypal API interface) which manages billing. To delete an account, I must delete the records from both. ...
1
vote
1answer
754 views

LPTHW - ex48 - Handling exceptions and unit testing

This is my solution to the exercise 48 of Learn Python the hard way by Zed Shaw. Please visit the link for testing suite and requirements. I'm worried about my the word banks I have created (COMPASS, ...
3
votes
2answers
8k views

HttpClient error handling

I would be happy to hear feedback on my implementation of HttpClient. I am not so strong with error handling so I want to improve. My thought process behind this was that ...
0
votes
1answer
97 views

uplifitng return value error reporting to Exception based error reporting

In Framework Design guideline book there is a chapter about Exception and they talk about return-value-based error reporting and exception based error reporting and the fact that we in a O.O language ...
3
votes
2answers
1k views

Is this right way to implement Abort, Retry and Ignore activity pattern?

I've a bunch of sequential activities. These are long running. Once an activity is complete, it can't be rolled back. Now something deep down the line fails. Now I've few options Report this to end ...
1
vote
1answer
548 views

PHP - Is this proper use of exceptions for error handling within classes?

I've searched plenty on this topic and have gotten a lot of good (but different) results. Some of the results weren't quite related and it does seem to be a matter of preference in the end, but I'm ...
3
votes
1answer
561 views

PHP error handling: log everything, and redirect critical errors to an “oops” page

I'm VERY new to error/exception handling, previously just echoing everything to screen, and am trying to really clean up my code. My goal was to log everything but only show the user a friendly "oops"...
2
votes
2answers
206 views

extending Exception to allow for auto appending class name on exception message

Got this idea from the php.net website on extending exceptions. The main thing I wanted with this was to have the exception name auto imprinted on the exception message, so I wouldn't have to write it ...
2
votes
1answer
68 views

How can I improve CreateGenre() function?

I use this function in my wordpress site to add genres to an album: What is it that makes this code so bulky? Is it have for the server or it just looks like? ...
2
votes
3answers
13k views

Exception handling continuing the excecution

This code is for continuing the execution after an exception, and this is ugly: ...
6
votes
2answers
264 views

Asserting when cleanup is required

I've been looking at ways to use asserts in programs that must do some kind of cleanup on fatal errors, and have arrived at the following pattern (PROJECT being replaced by the name of the project): <...
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 ...
3
votes
1answer
327 views

Tips for Python build scripts?

File manipulation code, I've noticed, has two salient properties: It's everywhere, and vitally important to functional software It has lots of exceptions. Please give me some pointers on ...
2
votes
3answers
374 views

Collecting form errors to be displayed

I have a piece of code that get errors from form and display to view: ...
2
votes
2answers
272 views

Is it acceptable to pass an Exception into a function that then may or may not throw it?

I am still getting the hang of Exception Handling in PHP; Here is the scenario where I am using the convention: There are times where I have a SQL query that I need to turn into an object, so I wrote ...
2
votes
3answers
102 views

Replace first occurrence of pattern in file

Here's my attempt to replace first occurrence of pattern in file with spaces. Effectively deleting it, and hopefully will allow me to "delete" it in a large file, ...
7
votes
6answers
16k views

Could this ExecuteScalar call be written better?

I came across this code in our project today. Where possible I'm trying to leave the code base in a better shape than I found it, as I go along, and this method jumped out at me for a number of ...
2
votes
1answer
7k views

Validating files and returning errors messages/boolean values

I am writing simple file validator for my java ee app and I am stack with my class api. I need specific error descriptions, but also I would like to have boolean values indicating whether file is ...
3
votes
2answers
181 views
10
votes
1answer
1k views

SQL Server stored procedure boilerplate

What would you do to improve upon this boilerplate empty stored procedure, being mindful of the delicate balance between length, complexity, performance and clarity? ...
2
votes
1answer
235 views

Is This a Sufficient Demonstration of the Effects of Exception Handling [closed]

We have some developers in house that believe it is best practice to use exception handing as flow control, as well as, thinking that catching and re-throwing exceptions is effective error handling. ...
7
votes
6answers
12k 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 ...
18
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 ...
4
votes
2answers
469 views

Open database and hande errors

How to make this code better? ...
4
votes
3answers
825 views

Making a job completed, rolling back on error

I have the following construction in the program: ...
8
votes
5answers
5k views

Aborting a program for invalid floating-point input

My friend does a bunch of Java work (commandline, still toying around) and I notice a bunch of try/catch blocks like this: ...
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: ...
9
votes
5answers
3k views

Providing unchecked exception “wrapper” interfaces for an API with checked exceptions

I recently had a discussion in the forum of an API, because they changed an exception from checked to unchecked. I believed it needs to be checked, because it is recoverable. The arguments of "the ...