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

learn more… | top users | synonyms

1
vote
3answers
203 views

When is a catch clause empty [duplicate]

I saw lots of questions and explanations regarding empty catch clauses but I was never actually sure what "empty" means. Is a catch clause like this empty? It clearly isn't empty for the eye because ...
2
votes
3answers
122 views

Avoiding null in a controller

I'm trying to work through how to write this code. def get(params): """ Fetch a user's details, or 404 """ user = User.fetch_by_id(params['id']) if not user: abort(404) # ...
7
votes
6answers
958 views

If the model is validating the data, shouldn't it throw exceptions on bad input?

Reading this SO question it seems that throwing exceptions for validating user input is frowned upon. But who should validate this data? In my applications, all validations are done in the business ...
2
votes
4answers
181 views

How do you hide error handling? [duplicate]

Many people consider exceptions to be a problem because they create invisible paths through your code. For example in this snippet: function writeToFile(text, filename): filehandle = open(filename) ...
1
vote
1answer
253 views

Does this violate the using exceptions for flow control “rule”?

I plan to make use of this interface in a plug-in architecture. /// <summary> /// Generic interface allowing you to react to an event. /// You can block the event or just use it for ...
-1
votes
6answers
1k views

Converting an empty string to a number [closed]

If you are designing a function which should conver a string to an integer, how would you convert an empty string? The question is only about this one particular input value (empty string). Between ...
5
votes
8answers
899 views

Best Practice for Argument Checking

Say I have a web service with a method MyWebServiceMethod(string passedValue). The web service calls a method MyServiceMethod(string passedValue) where the value from the web service is passed along. ...
22
votes
5answers
7k views

Why is there no 'finally' construct in C++?

Exception handling in C++ is limited to try/throw/catch. Unlike Object Pascal, Java, C# and Python, even in C++ 11, the finally construct has not been implemented. I have seen an awful lot of C++ ...
1
vote
2answers
607 views

Assertions vs Exceptions - is my understanding of the differences between the two correct? [duplicate]

Design By Contract uses preconditions and postconditions of the public methods in a class together to form a contract between the class and its clients. a) In code we implement preconditions ...
22
votes
3answers
871 views

Why is Option/Maybe considered a good idea and checked exceptions are not?

Some programming languages like e.g. Scala have the concept of Option types (also called Maybe), which can either contain a value or not. From what I've read about them they are considered widely to ...
1
vote
2answers
233 views

Wrapping specific checked exception in domain unchecked ones? [duplicate]

Uncle Bob says in Clean Code book that Unchecked Exceptions should be used. Now JDK has some checked exceptions: IOException, IllegalAccessException etc. which cannot be avoided. In my application ...
2
votes
7answers
569 views

better way to define an exception thrown by a method in Java?

I know how to define exceptions and all, but I'm not sure if the way I'm doing it is the most intuitive and readable by another users. I have a very simple method I've written that I want to throw an ...
16
votes
3answers
1k views

How many are too many nested function calls?

Quoted from MSDN about StackOverflowException: The exception that is thrown when the execution stack overflows because it contains too many nested method calls. Too many is pretty vague here. ...
11
votes
5answers
4k views

Are exceptions as control flow considered a serious antipattern? If so, Why?

Back in the late 90's I worked quite a bit with a code base that used exceptions as flow control. It implemented a finite state machine to drive telephony applications. Lately I am reminded of those ...
8
votes
3answers
5k views

Throwing an exception inside finally

Static code analyzers like Fortify "complain" when an exception might be thrown inside a finally block, saying that Using a throw statement inside a finally block breaks the logical progression ...
7
votes
2answers
279 views

The suffix Exception on exceptions in java

Specifying a suffix of Exception on exception classes feels like a code smell to me (Redundant information - the rest of the name implies an error state and it inherits from Exception). However, it ...
0
votes
2answers
176 views

Is there anything special to consider when writing my own exception class in C++? [closed]

If I wanted to implement my own version of the std::exception for no good reason, are there any special things about implementing this kind of object that I should be aware of? It seems like a fairly ...
-1
votes
1answer
151 views

Good library for combining .net stack traces [closed]

I currently report my production exceptions to a mysql database, where they have been collecting dust for the most part. The problem I faced is grouping the stack traces. I would like to be able to ...
1
vote
2answers
310 views

Why does File.Open in .Net throw exceptions and not follow exception handling best practices? [duplicate]

I have read at many places including this - http://msdn.microsoft.com/en-us/library/seyhszts.aspx - that you should use exception handling when something is truly exceptional. The .Net File.Open ...
3
votes
2answers
579 views

How to remove duplicate exception block code

I have good number of Service and DAO classes which has the same set of 30 line exception code block which gets repeated and it shows up in Code Duplication report. The approach which i can think of ...
7
votes
5answers
6k views

throwing runtime exception in Java application

I am working as a contractor designing enterprise Java application for my client in the role of a technical lead. The application will be used by end users and there will be a support team who will ...
54
votes
11answers
4k 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. ...
33
votes
8answers
3k views

Are exceptions an OOP concept?

Having read a post yesterday, I realized I did not know much about the origin of exceptions. Is it an OOP related concept only? I tend to think it is, but again there are database exceptions.
2
votes
1answer
97 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
505 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 ...
6
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
892 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 ...
30
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
117 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
302 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
336 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 ...
2
votes
4answers
170 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 ? ...
39
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 ...
27
votes
9answers
8k 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
761 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
4k 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
4k 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
466 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", ...
15
votes
5answers
4k 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. ...
25
votes
4answers
10k 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
1k 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 ...