An exception is an occurrence in an application process that requires deviation from the program's normal flow.

learn more… | top users | synonyms

2
votes
1answer
98 views

Data decoding initialization/Constructor error handling

I have a set of loadable data decoders for a specific type of data and a stream to read containing data. Now I want the program to select the correct decoder in a reliable way so I want to use a ...
4
votes
4answers
625 views

Having error codes option in C++ library for performance

I have written an open source and cross-platform C++ File Library which have exception and error codes. Exceptions can be disabled when the program is running. In that case, the user have to check the ...
7
votes
2answers
1k views

Decision for Unchecked Exceptions in Scala

As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) ...
8
votes
5answers
959 views

“Programming error” exceptions - Is my approach sound?

I am currently trying to improve my use of exceptions, and found the important distinction between exceptions that signify programming errors (e.g. someone passed null as argument, or called a method ...
32
votes
3answers
2k views

Python Forgiveness vs. Permission and Duck Typing

In Python, I often hear that it is better to "beg forgiveness" (exception catching) instead of "ask permission" (type/condition checking). In regards to enforcing duck typing in Python, is this try: ...
4
votes
3answers
118 views

Designing exceptions for conversion failures

Suppose there are some methods to convert from "X" to "Y" and vice versa; the conversion may fail in some cases, and exceptions are used to signal conversion errors in those cases. Which would be the ...
9
votes
2answers
323 views

Use an else after exception (or not)

Consider this bit of code: if (x == 1) { throw "no good; aborting" ; } [... more code ...] Now consider this code: if (x == 1) { throw "no good; aborting" ; } else { [... more code ...] } ...
6
votes
2answers
431 views

Where should I handle fatal exceptions

Suppose I have a controller that loads a file and hands it over to the processing. Should I handle the exception in the file loader and return Null if something is wrong, or should I throw the ...
1
vote
4answers
174 views

What is the best way to go about testing that we handle failures appropriately?

we're working on error handling in an application. We try to have fairly good automated test coverage. One big problem though is that we don't really know of a way to test some of our error handling. ...
2
votes
3answers
2k views

Best method in PHP for the Error Handling ? Convert all PHP errors (warnings notices etc) to exceptions?

What is the best method in PHP for the Error Handling ? is there a way in PHP to Convert all PHP errors (warnings notices etc) to exceptions ? what the best way/practise to error handling ? ...
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 ...
30
votes
10answers
10k views

Is catching general exceptions really a bad thing?

I typically agree with most code analysis warnings, and I try to adhere to them. However, I'm having a harder time with this one: CA1031: Do not catch general exception types I understand the ...
35
votes
12answers
2k views

Why are errors named as “Exception” but not as “Error” in programming languages?

I've been thinking about that for quite a while actually. I am not a native english speaker myself but still I have years of programming experience and I always asked me this. Why is it named as ...
0
votes
1answer
1k views

Generic way of handling exceptions in windows phone? [closed]

I mean what are some of the ways other programmers deal with exception for example, when an error occurs when accessing a web service for say. If an example cant be given for windows phone, give the ...
8
votes
1answer
1k views

Best exception handling practices or recommendations? [closed]

I think the two main problems with my programs are my code structure/organization and my error handling. I'm reading Code Complete 2, but I need something to read for working with potential problems. ...
2
votes
3answers
930 views

Good practice or service for monitoring unhandled application errors for a small organization

I'm working with multiple software with varying ways of monitoring for errors. When I make software, I usually send email with the stack trace to admins(usually me). Some customer software is ...
9
votes
6answers
2k views

Maybe monad vs exceptions

I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax. update Please note that I'm intentionally ...
1
vote
2answers
1k views

Exception hierarchy design

In my company we are building a webapp containing serveral central services that we design ourselves and then specify as interfaces. I.e. the interfaces are application specific and they are then ...
3
votes
3answers
134 views

Using Exception Emails as a System Status Indicator

I'm working through our bug list today and I'm trying to clear up/fix issues that we commonly receive exception emails for. Although all the exceptions (so far) are handled, some don't actually ...
26
votes
5answers
2k views

Is use of finally clause for doing work after return bad style/dangerous?

As part of writing an Iterator, I found myself writing the following piece of code (stripping error handling) public T next() { try { return next; } finally { next = ...
15
votes
6answers
5k views

Efficient try / catch block usage?

Should catch blocks be used for writing logic i.e. handle flow control etc? Or just for throwing exceptions? Does it effect efficiency or maintainability of code? What are the side effects (if there ...
11
votes
9answers
5k views

if/else statements or exceptions [duplicate]

Possible Duplicate: Defensive Programming vs Exception Handling? I don't know, that this question fit better on this site, or Stack Overflow, but because my question is connected rather to ...
4
votes
2answers
522 views

I have a stacktrace and limit of 250 characters for a bug report

I'm developing an xbox indie game and as a last-resort I have a try...catch encompassing everything. At this point if an exception is raised I can get the user to send me a message through the xbox ...
1
vote
3answers
94 views

Communicating details of method result?

I have code like this (pseudocode) foreach(Box box in boxes) { if(boxFilter.PassesFilter(box)) { // do something useful } else { Log.Log(format("Box %s was rejected", ...
18
votes
5answers
5k views

should I throw exception from constructor?

I know I can throw exception from constructor in PHP but should I do it? For example, if a parameter's value is not as I expected it. Or should I defer throwing an exception till a method is invoked. ...
34
votes
4answers
13k views

Is it better to use assert or IllegalArgumentException for required method parameters?

In Java, which is more highly recommended, and why? Both types will throw exceptions, so in that regard handling them is the same. assert is slightly shorter, but I'm not sure how much that matters. ...
3
votes
1answer
2k views

Unit testing invalid inputs; ArgumentException vs. Custom Exception

In unit tested code I often have multiple checks on the arguments on any method before the actual "work" of the method is begun: public void DoSomething(string test) { if ...
8
votes
8answers
1k views

Using a try-finally (without catch) vs enum-state validation

I have been reading the advice on this question about how an exception should be dealt with as close to where it is raised as possible. My dilemma on the best practice is whether one should use a ...
8
votes
4answers
1k views

Exceptions as asserts or as errors?

I'm a professional C programmer and a hobbyist Obj-C programmer (OS X). Recently I've been tempted to expand into C++, because of its very rich syntax. So far coding I haven't dealt much with ...
16
votes
3answers
762 views

How to avoid throwing vexing exceptions?

Reading Eric Lippert's article on exceptions was definitely an eye opener on how I should approach exceptions, both as the producer and as the consumer. However, I'm still struggling to define a ...
8
votes
4answers
1k views

Is rethrowing an exception leaking an abstraction?

I have an interface method that states in documentation it will throw a specific type of exception. An implementation of that method uses something that throws an exception. The internal exception ...
8
votes
2answers
397 views

How can I debug exceptions that are not easily reproducible and only occur in a production environment?

I am working on an issue where the exception only occurs in our production environment. I don't have access to these environments, nor do I know what this exception means. Looking at the error ...
49
votes
7answers
31k views

Why use try … finally without a catch clause?

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do ...
18
votes
6answers
38k views

Why doesn't “object reference not set to an instance of an object” tell us which object?

We're launching a system, and we sometimes get the famous exception NullReferenceException with the message Object reference not set to an instance of an object. However, in a method where we have ...
4
votes
2answers
307 views

Nulls in every type and checked exceptions in Java?

I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that ...
8
votes
7answers
1k views

Use of NotImplementedException

Is it considered bad practice to throw NotImplementedException for code you haven't written yet? Possibly TODO comments would be considered safer?
3
votes
3answers
3k views

How to store exception messages

How are exception messages commonly stored? for any domain. I'm thinking about this from a maintenance standpoint. if(!Condition1) throw new Exception("Some exception"); if(!Condition2) ...
0
votes
2answers
438 views

Is it possible to prune the stacktrace returned for a custom exception in PHP

I am working on a project in PHP that does a lot of input validation and can throw different custom exception classes in various layers of the application. To make the project code easier to read, ...
2
votes
3answers
749 views

What do you think of this Exception handling practice

I'm working on a project that includes a lot of creating/manipulating and reading JSONObjects and arrays but not in a systematic way. So there is JSON code everywhere. It is ok for me except that ...
0
votes
2answers
722 views

A good substitute for ASMX web service methods, but not a general handler

The best thing I like about ASP.NET MVC, is that you can directly call a server method (called action), from the client. This is so convenient, and so straightforward, that I really like to implement ...
8
votes
9answers
814 views

Should security restrictions cause a service to return null or throw an exception?

I'm in a bit of a disagreement with a more experienced developer on this issue, and wondering what others think about it; our environment is Java, EJB 3, services, etc. The code I wrote calls a ...
13
votes
2answers
1k views

Is it more sensible to log exceptions in a catch-all or in a base exception class?

I'm in the process of refactoring a fairly large web app. One of the major issues is inconsistent error handling and I'm trying to come up with a sensible strategy. I've created a custom error ...
27
votes
11answers
10k views

Is it good practice to catch a checked exception and throw a RuntimeException?

I read some code of a colleague and found that he often catches various exceptions and then always throws a 'RuntimeException' instead. I always thought this is very bad practice. Am I wrong?
9
votes
5answers
5k views

Throwing and catching exceptions in the same function/method

I've written a function that asks a user for input until user enters a positive integer (a natural number). Somebody said I shouldn't throw and catch exceptions in my function and should let the ...
13
votes
2answers
1k views

What is a 'good number' of exceptions to implement for my library?

I've always wondered how many different exception classes I should implement and throw for various pieces of my software. My particular development is usually C++/C#/Java related, but I believe this ...
16
votes
10answers
1k views

Why not use the word bug instead of exception? [closed]

If we refer to exceptions as bugs, why not just call it a bug in the first place instead of an exception? If in the code it's called exception and as soon as it occurs it's called a bug. Then why not ...
13
votes
7answers
1k views

Do exceptions basically exist to prevent a system from crashing?

Second of all, I was wondering if anyone knew what the difference was between exceptions (in the realm of exception control flow) and Exceptions (such as used in Java). But are they there to ...
26
votes
3answers
7k views

Why are exception specifications bad?

Back in school some 10+ years ago, they were teaching you to use exception specifiers. Since my background is as one of them Torvaldish C programmers who stubbornly avoids C++ unless forced to, I only ...
2
votes
1answer
95 views

What are possible/useful implementations when extending exceptions?

I have seen a lot of exceptions - custom or integrated in the language (PHP) itself that have no differences but their class name. When extending default exceptions to use within your own code, are ...
21
votes
4answers
8k views

Why do iterators in Python raise an exception?

Here's the syntax for iterators in Java (somewhat similar syntax in C#): Iterator it = sequence.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Which makes sense. Here's ...