Questions related to handling errors and exceptions. According to Wikipedia, Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution. It ...

learn more… | top users | synonyms

0
votes
3answers
86 views

Coerce bad input or always crash early

The general consensus seems to favor the Crash Early approach, the most reputable source being the acclaimed Pragmatic Programmer book. And while I understand and agree with the advice in many ...
5
votes
2answers
498 views

How should I handle logger failures?

In several of our company's applications, we use a custom logger. It's fairly robust, though we may replace it with something like NLog in the future. One of the logger's tasks is to log any ...
30
votes
20answers
2k views

How do you tackle really bizarre errors that keep you puzzled for more than 10 hours? [closed]

You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle?
2
votes
2answers
93 views

Preferred way of handling errors when loading an object from a file

If I want to load an object from a file, there are a number of things that can go wrong. Thus, one needs a way of handling errors when doing so. In some languages, like haskell, one can return a Maybe ...
-1
votes
0answers
22 views

Get defines dynamically for messages [migrated]

In this following code, i want to use predefined message for my errors_manager function, with the macro CALL_MSG(). but when i use an variable, i can't get the content of the variable ! err = ILLOPS ...
0
votes
0answers
42 views

When calculating cyclomatic complexity, should Exception Handling considered? [duplicate]

When calculating the cyclomatic complexity of a piece of code (/method/program), should any Exception Handling be taken into account? For example, if you include a try-catch block in your ...
7
votes
2answers
565 views

What's the difference between robustness and fault-tolerance?

Systems / programs / distributed algorithms / ... are often described with the predicate robust or fault-tolerant. What is the difference? Details: When I google for +robust +"fault-tolerant", I ...
3
votes
1answer
403 views

MVC: Where is the right place to set error messages?

I have a ASP.NET MVC application where in all my Models have an Errors Property used to store non-validation errors which I than display in my Views. Where is the right place to populate the error ...
28
votes
8answers
1k views

Is it okay to use exceptions as tools to “catch” errors early?

I use exceptions to catch problems early. For example: public int getAverageAge(Person p1, Person p2){ if(p1 == null || p2 == null) throw new IllegalArgumentException("One or more of ...
4
votes
2answers
107 views

Defining error codes

We are designing an error-handling framework for a cryptographic library written in C. The approach we are taking is that relatively few errors are propagated back to the user since on most occasions ...
1
vote
0answers
88 views

Handling and managing error codes

I'm looking for examples of creating, handling and managing error numbers/codes. To understand what I'm takling about, let's take example scenario: (EU - end user, IT - it helpdesk) EU: - (calls IT) ...
7
votes
2answers
719 views

How to Implement Error Handling [closed]

Even though I've programmed on a professional level for some years I still do not fully understand error handling. Although my applications work fine, the error handling isn't implemented at a ...
4
votes
1answer
175 views

Error Handling Strategies in Multithreaded Environments

TL;DR What error generating and handling strategies do you use in Multithreaded code intended for use by others and why do you use them? If applicable, state what programming paradigm it's useful for. ...
-4
votes
1answer
112 views

Try and catch error trapping, why is it so significant? [duplicate]

I try to understand why should I "try" a method to catch errors. It looks to me like the concept is: "letting a process run assuming its not properly developed". Should I always assume that a ...
1
vote
2answers
202 views

Is goto to improve DRY-ness OK?

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
9
votes
2answers
193 views

Cleanest way to report errors in Haskell

I'm working on learning Haskell, and I've come across three different ways of dealing with errors in functions I write: I can simply write error "Some error message.", which throws an exception. I ...
10
votes
6answers
1k views

Designing database related methods, which is better to return: true/false or row affected?

I have some methods that perform some data changing in a database (insert, update, and delete). The ORM I'm using return row-affected int values for those type of method. What should I return for "my ...
21
votes
15answers
8k views

Arguments for or against using Try/Catch as logical operators [closed]

I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators. Meaning, "do some code, if that throws this error, do this code, but if that throws this error ...
61
votes
14answers
12k views

Why is 0 false?

This question may sound dumb, but why does 0 evaluates to false and any other [integer] value to true is most of programming languages? String comparison Since the question seems a little bit too ...
10
votes
4answers
3k views

`trigger_error` vs `throw Exception` in the context of PHP's magic methods

I'm having a debate with a colleague over the correct usage (if any) of trigger_error in the context of magic methods. Firstly, I think that trigger_error should be avoided except for this one case. ...
29
votes
4answers
1k views

How much information about an error should be shown to the user?

Applications can always throw errors. If such an error occurs, the user should be notified, because what he asked the application to do has not succeeded. However, how much information should the ...
56
votes
16answers
20k views

How to handle divide by zero in a language that doesn't support exceptions?

I'm in the middle of developing a new programming language to solve some business requirements, and this language is targeted at novice users. So there is no support for exception handling in the ...
4
votes
4answers
2k views

Exceptions vs ErrorCodes when working with devices

Out team is at the cusp of a new project. One of the components at the boundary of the system is the component which interacts with a printer through an external COM component (referenced as a usual ...
6
votes
5answers
692 views

Checked vs Unchecked vs No Exception… A best practice of contrary beliefs

There are many requirements needed for a system to properly convey and handle exceptions. There are also many options for a language to choose from to implement the concept. Requirements for ...
0
votes
2answers
305 views

IllegalStateException vs. IllegalArgumentException

In have written a function which expects the caller to pass in a configuration file like XML. Then I parse this given file and extract something which i then return. In this function (at least) two ...
2
votes
0answers
111 views

Is there a theory for “transactional” sequences of failing and no-fail actions?

My question is about writing transaction-like functions that execute sequences of actions, some of which may fail. It is related to the general C++ principle "destructors can't throw," no-fail ...
14
votes
5answers
15k views

try-catch in javascript… isn't it a good practice?

There is a provision for try-catch block in javascript. While in java or any other language it is mandatory to have error handling, I don't see anybody using them in javascript for greater extent. ...
1
vote
2answers
251 views

global try-catch in presentation layer

I have a 3-layered app structured as follows. Presentation Layer (ASP.NET MVC project) Business Logic Layer (Services for controllers in PL) Data Access Layer (Repositories) Each Controller in PL ...
3
votes
2answers
129 views

What is better to return from the DataService: Status or Exceptions?

I have a MVVM app with DataServices (using mvvmlight). Right now, i'm using it like var answer = await myDataService.PullList(categoryId); if (answer.Status == Ok) ...
2
votes
1answer
80 views

How to handle errors best addressed in a higher abstraction layer and dependent on state inferred in current layer?

I have a use-case that can be repaired, but the logic for repairing it is best done in a higher level of abstraction. Just throwing exception/failure is ugly because it's hard to pass back up through ...
2
votes
1answer
253 views

Passing multiple errors back from service layer

I am using Spring for a web application. To validate a user's input in a form such as for creating a Person entity I user JSR 303 validation to check for not null/empty or valid patterns etc.. Some ...
3
votes
6answers
1k views

Whats the best way to handle errors in code?

So I'm a little concerned about my error handling... Currently my execution path looks something like this: Users.aspx -> App_Code/User.cs -> Data Layer/User.cs So now when I try to update a ...
0
votes
2answers
51 views

Handling ignorable failure conditions in a method

I'm working on a coarse API for performing higher level business functions. Under many conditions these functions may fail in a way that is expected (not exceptional), ie. the function may not be ...
13
votes
5answers
4k views

null pointers vs. Null Object Pattern

Attribution: This grew out of a related P.SE question My background is in C / C++, but I have worked a fair amount in Java and am currently coding C#. Because of my C background, checking passed and ...
3
votes
5answers
843 views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
2
votes
1answer
183 views

Error Handling when no access to Visual Studio or application start point

I've recently joined a project where we are extending the functionality of an external application that our company has bought. It is an Office Add-In with an admin console that allows you to create ...
-1
votes
1answer
167 views

Functions returning either “OK” or “error message” instead of procedures

I have joined writing middle-size multi-purpose database application as co-lead. It currently has about 150 tables (and growing) and overall functionality you can imagine as very small ERP. At many ...
1
vote
1answer
66 views

Automating form error handling

I'm not sure if I'm being clever or making things more difficult. I'm working within a custom MVC framework, and within some of my "views" which contain forms I'm preserving input and styling errors ...
3
votes
1answer
99 views

Invalid data returned, which HttpCode to return?

My web application calls a third party API. If I successfully call the API but invalid data is returned which cannot be processed by my system what is the most appropriate HttpCode to return to the ...
0
votes
0answers
74 views

Check some value between each function call

Can you recommend a nice way of checking a particular value between calls to a set of functions? E.g. something like this in Python (might not be terribly 'Pythonic'): self.error_code = 0 # this ...
1
vote
1answer
55 views

Partial recovery from an Exception [duplicate]

I have seen Exception Handling blocks that they were throwing the recently caught Exception in the catch block. Something like: } catch ( Exception $e ) { // Do some recovery here ...
1
vote
2answers
1k views

Python - assert vs if & return

I am writing a script that does something to a text file (what it does is irrelevant for my question though). So before I do something to the file I want to check if the file exists. I can do this no ...
61
votes
14answers
10k views

Should one check for null if he does not expect null?

Last week, we had a heated argument about handling nulls in our application's service layer. The question is in the .NET context, but it will be the same in Java and many other technologies. The ...
0
votes
5answers
247 views

Fail-fast paradigm overheads

Fail-fast seems like a right way since it simplifies bug detection. But it's a harm for performance cause of multiple checking the same thing at several levels of the system. Simple example. There is ...
40
votes
10answers
3k views

Why are exceptions considered better than explicit error testing? [duplicate]

Possible Duplicate: Defensive Programming vs Exception Handling? if/else statements or exceptions I often come across heated blog posts where the author uses the argument: "exceptions vs ...
8
votes
3answers
1k views

Exceptions or Error codes

We are building a web service(SOAP, .Net) which would be talking to (mostly) native clients (windows, C++) and we are wondering what is the best way to communicate errors to the client (e.g. ...
5
votes
3answers
985 views

Authoritative sources for exception handling best practices [closed]

My work place suffers from a bad case of the Pokemon Exception Handling anti-pattern with constructs like the following splattered across the code base: try { ... } catch (Exception ex) { // ...
8
votes
4answers
647 views

Is error suppressing bad practice?

On a SO question I asked here about some code I was unsure about, someone replied "BTW, horrible code there: it uses the error suppressing symbol (@) a lot." Is there a reason why this is bad ...
54
votes
11answers
5k views

I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. ...
2
votes
4answers
653 views

Should I achieve validation by handling errors in classic ASP?

I came across this while modifying an old ASP application: ON ERROR RESUME NEXT ivalue = CDATE(ivalue) IF err.number > 0 THEN ivalue = CDATE(date) END IF err.clear This doesn't look like ...