An exception is an occurrence in an application process that requires deviation from the program's normal flow.
-1
votes
1answer
112 views
Making my code more robust [closed]
I have recently finished a piece of code that passed all tests.
(Here is some idea what it does and Here is some actual code.)
Problems began, however, when I run my code on the cloud with actual ...
2
votes
1answer
83 views
How to handle when one user deletes the object while the other has it opened in edit mode in a webapp?
I am developing a CRUD type web application. It is a project management system having projects, milestones, tasks, employees etc. Each employee has his/her own account to login and view the system. ...
1
vote
1answer
117 views
Either Monad and Exceptional Circumstances [duplicate]
I have a function returning an Either such as GetUserFromDb(int id).
If the database is offline, should I catch the error in the function and wrap it in a failure / Left case or should I let it ...
7
votes
3answers
139 views
When and how should I use exceptions (in Python)?
The Setting
I often have trouble determining when and how to use exceptions. Let's consider a simple example: suppose I am scraping a webpage, say "http://www.abevigoda.com/", to determine if Abe ...
0
votes
2answers
124 views
Is storing stack traces in database recommended?
The current system I am working on goes through a set of documents & performs some logic using the metadata of the document. If the metadata of a document is fishy..it throws an exception. The ...
3
votes
1answer
133 views
Understanding exceptional cases
I've been studying the use of exceptions in various php projects (such as Doctrine and Zend Framework). Exceptions seem to be thrown when unordinary input/state occurs. A perfect example is Doctrine ...
5
votes
4answers
489 views
What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]
AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
2
votes
3answers
298 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 ...
1
vote
4answers
324 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
136 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
314 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
259 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
200 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 ...
37
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
188 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
197 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
114 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)
# ...
6
votes
5answers
508 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
159 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
197 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
405 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
503 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.
...
19
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
376 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
776 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
188 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
352 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
966 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
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
2k 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
235 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
158 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
113 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
231 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
344 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
3k 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 ...
51
votes
11answers
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
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
89 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
387 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 ...
5
votes
2answers
617 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
545 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 ...
26
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 ...
8
votes
2answers
284 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
228 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
157 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
1k 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 ...
23
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 ...