An exception is an occurrence in an application process that requires deviation from the program's normal flow.
2
votes
3answers
195 views
Layering Design Pattern in Java clean code style
As a Java developer, I am developing trying to use the clean code rules. But in my team we are facing a concrete problem:
We have a business layer offering a service called "createObject", this ...
-4
votes
1answer
104 views
What are Exceptions (checked and unchecked) in Java? [closed]
What is the difference between checked and unchecked exceptions in java?
Why do we throw using 'throws' exception instead of catching them?
1
vote
4answers
306 views
What's the difference between the code inside a finally clause and the code located after catch clause?
My java code is just like below:
public void check()throws MissingParamException{
......
}
public static void main(){
PrintWriter out = response.getWriter();
try {
check();
} ...
3
votes
3answers
114 views
Throwing exception from a property when my object state is invalid [duplicate]
I am aware that for the general case, the answer to "should I throw an exception from a property" is "generally don't, but in some special circumstances it is OK to do so". There is a Microsoft ...
2
votes
3answers
281 views
What code lays behind C++ exception?
In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data ...
2
votes
1answer
236 views
Why would one transform a checked exception to an unchecked exception? [duplicate]
My buddy told me today that some programmers transform a checked exception (e.g. EJBException, SQLException...) to an unchecked (RuntimeException?)
My buddy explained a call stack where if you change ...
1
vote
2answers
190 views
Java exception redundancy
To what extent should one make exceptions redundant or atomic to a method.
For instance, suppose I have a method public void authenticate(String username, String password) that calls private void ...
36
votes
7answers
2k views
Are there legitimate reasons for returning exception objects instead of throwing them?
This question is intended to apply to any OO programming language that supports exception handling; I am using C# for illustrative purposes only.
Exceptions are usually intended to be raised when an ...
1
vote
3answers
176 views
Throwing an exception for errors that can be fixed
Say I have a class like this:
public class MyObject
{
public List<string> MyCollection { get; set; }
}
And a method like this:
public void DoSomething(MyObject object)
{
...
0
votes
3answers
191 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
113 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)
# ...
5
votes
5answers
427 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
149 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
166 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
287 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 ...
4
votes
8answers
438 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.
...
17
votes
5answers
4k 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
297 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 ...
21
votes
3answers
753 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
166 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
293 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 ...
15
votes
3answers
868 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. ...
9
votes
5answers
2k 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 ...
6
votes
3answers
836 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
221 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
153 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
107 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 ...
2
votes
3answers
216 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
311 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 ...
5
votes
5answers
2k 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 ...
46
votes
10answers
3k 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
2k 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
86 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
355 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 ...
4
votes
2answers
442 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) ...
6
votes
4answers
518 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 ...
25
votes
3answers
1k 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 ...
8
votes
2answers
278 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
214 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
154 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
903 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 ?
...
37
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 ...
22
votes
9answers
5k 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 ...
34
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
631 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 ...
7
votes
1answer
690 views
Best exception handling practices or recommendations?
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
458 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 ...
7
votes
5answers
914 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
916 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 ...