An exception is an occurrence in an application process that requires deviation from the program's normal flow.
11
votes
5answers
160 views
Should I log errors on exception throwing constructors?
I was building an application for a few months and I come to realize a pattern that emerged:
logger.error(ERROR_MSG);
throw new Exception(ERROR_MSG);
Or, when catching:
try {
// ...block that ...
5
votes
2answers
183 views
How to get around non-initialized objects in the `finally` block?
I like using final variables whenever possible. Often those variables have to be closed afterwards. Note that I'm currently working on Java 6 so there is not closeable interface, but the same applies ...
17
votes
3answers
2k views
Exceptions - “what happened” vs “what to do”
We use exceptions to let the consumer of the code handle unexpected behaviour in a useful way. Usually exceptions are built around "what happened" scenario - like FileNotFound (we were unable to find ...
6
votes
2answers
840 views
Should one derive / inherit from std::exception?
While designing my first 'serious' C++ library, I'm asking myself:
Is it good style to derive ones exceptions from std::exception and it's offsprings?!
Even after reading
Designing exception ...
4
votes
3answers
93 views
Drawbacks of a master error handler?
I'm thinking that I could simplify my life by making an exception handling class that I can just ship all exceptions to and it will handle appropriately.
Ideally:
def dostuff():
try:
dothis()
...
0
votes
1answer
38 views
Include exceptions in activity diagrams? [closed]
Should I include exceptions, like a TimeOutException or just general Exceptions, to a activity diagram?
For example: A activity diagram describing a client-server connection. Several exceptions can ...
10
votes
5answers
544 views
What is the conceptual difference between finally and a destructor?
First, I am well aware of Why is there no 'finally' construct in C++? but a lengthy-growing comment discussion on another question seems to warrant a separate question.
Apart from the issue ...
-3
votes
2answers
129 views
Why ever use exception throw (in C#) except for Class Library development? [duplicate]
Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change).
To be more specific, ...
2
votes
3answers
83 views
Is there particular circumstance that throwing root superclass exceptions is a good practice?
I've been taught that exceptions should be have concise meanings and should contain a message that explains to the client what the exceptional situation is. I am wondering, since I found a piece of ...
8
votes
2answers
326 views
Is the strong exception safety guarantee with a pass-by-value argument which can throw on destruction possible?
Suppose you have a type with a throwing destructor, and a function receiving it by value.
Can that operation ever provide anything better than the basic exception guarantee?
Or formulated differently, ...
0
votes
1answer
141 views
Low cost exceptions implementation using metaprogramming [closed]
(preface - boring stuff, feel free to skip down to the implementation details)
I need to provide exception handling to a language I am working on. It "compiles" to a subset of C, and since I don't ...
2
votes
2answers
57 views
How can a method handle validation and entity creation without output parameters?
I have 3 simple classes. A Reference, a Parent, and a Child. The Child knows the Reference and Parent instances it's associated with. Here they are, initialization and other data/methods omitted:
...
2
votes
0answers
64 views
Handling exceptions in multiple-issue CPUs
From what I read, VLIWs execute instructions in bundles, i.e. the CPU loads a bundle of instructions and dispatches them all at once. This is possible because the compiler scheduled instructions in ...
3
votes
5answers
251 views
Is it bad practice to throw multiple custom exceptions in Java? [duplicate]
I'm developing a Java web application. It is a three layered architecture:
web > service > repository.
I'm thinking of creating many exceptions - each specific to each individual error and in the ...
5
votes
3answers
78 views
Recommendations for adding exceptions messages to code [closed]
The "problem" that I am having right now its quite simple, I am creating a code with A LOT of validations, in case one of those fails it is supposed to throw an exception.
In order to make the ...
21
votes
2answers
1k views
Who should read Exception.Message if at all?
When designing exceptions should I write messages that a user or a developer should understand? Who should actually be the reader of exception messages?
I find exception messages aren't useful at all ...
1
vote
1answer
120 views
How often should I use try/catch statements? [duplicate]
Everything I've read says that they should be used when something that simply "shouldn't happen" does happen. But the thing is, there's a lot of things that could go wrong.
For example, if I'm ...
2
votes
2answers
62 views
Advantages of extending the default Exception class
I've seen that it's possible to extend the default Exception class in PHP, enabling one to throw an IncorrectParameterTypeException exception, or a ValueOutOfRangeException exception (maybe these are ...
0
votes
1answer
107 views
Can I execute a query in a catch block of try-catch? [duplicate]
I want to confirm the right approach of using try-catch exception handler.
I have written a query in a try block, and if any exception is thrown, it will execute a query in a catch block.
Is this ...
1
vote
2answers
73 views
Throwing exceptions in application configuration providers
Simple question: What is the best/common practice regarding to throwing errors for application configuration providers?
Given is a simple key/value-based configuration source:
class Configuration
...
4
votes
4answers
207 views
Should exceptions be raised higher up or lower down or both? [closed]
When calling some function in a Python application, the function often calls functions deeper down which again call functions deeper down, etc. It is easy to unknowlingly pass a bad value to the ...
5
votes
2answers
203 views
Exception clutter, how necessary is it? [duplicate]
Let's say I have a few methods that access the File System, and I want them to be a bit robust, I want to throw errors so the user can react:
If the file doesn't have read / write rights, I want to ...
2
votes
2answers
164 views
Exception handling in Python - Am I doing this wrong (and why?)
I've read many questions and articles on exception handling in Python (and in general), but I still think that it's the most confusing thing ever. I ended up doing something like this:
# error class ...
1
vote
7answers
232 views
Throwing an exception when a method does not complete or implement a work around? [duplicate]
I have been studying this subject quite a bit, and I am unsure of what's the best way. I still have a lot to go trough (books, blogs, stack exchange, etc), but I simply can't find a consensus.
...
1
vote
1answer
115 views
Proper propagation / handling of exceptions
I am trying to learn trough example on a proper way to handle exceptions. When should I catch it, when and how should I throw it further down the line ?
In this example I have a very simple setup:
...
5
votes
2answers
308 views
Sending Exceptions as event arguments
Is it a good idea to send Exceptions as EventArgs in C#? (And not actually throw the Exception).
I have a class that performs a long running asynchronous task. If something goes wrong in the middle ...
7
votes
3answers
374 views
Should I make my own exceptions, or co-opt similar exceptions for slightly non-standard purposes?
This is a general design question, but I'm focusing on C# and .NET because those are the languages I'm working with right now.
Should I create my own, new exception classes, or co-opt existing ...
3
votes
3answers
109 views
Is this a valid situation for returning rather than throwing an exception?
This is not something I would ever normally do, but I have a situation where some existing legacy code is being reused in a new application. The code is shared and needs to be used by both the legacy ...
3
votes
2answers
123 views
Handling exceptions in a loop without breaking the loop (try to process all members)
Scenario:
I have a loop that iterates over an Array of COM objects and does some work using them.
My fear, working with COM objects, is that some exception will creep up (possibly on another ...
3
votes
4answers
168 views
Design strategy for wrapping exceptions
I'm implementing a type of Repository for a framework/library that has (roughly) the following:
public interface FooRepository {
boolean contains(String id);
Foo fetch(String id);
void ...
1
vote
2answers
66 views
Is it valid to expect/throw an exception using a custom caching system?
Imagine some code like the following:
class Cache {
private Map<String, String> values = new HashMap<String, String>();
public String getFromCache(String key) {
if ...
4
votes
3answers
149 views
Returning a Flag Indicating Success [closed]
Whenever I'm writing code, I always stub out my methods like this (not necessarily using generics):
public T MyMethod()
{
T result = default(T); // or null
return result;
}
This always ...
7
votes
1answer
181 views
Do we need to validate entire module usage or just arguments of public methods?
I've heard that it is recommended to validate arguments of public methods:
Should one check for null if he does not expect null?
Should a method validate its parameters?
MSDN - CA1062: Validate ...
4
votes
2answers
290 views
Rust-style error handling in C++
I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can ...
2
votes
2answers
82 views
Try Catch and Flow Control dilemma
I am aware that doing Flow Control on a program using a try-catch block is bad practice, but I can't see how to do it in another way when the error caught needs a redirection of the code's execution.
...
3
votes
1answer
78 views
Connection between futures and exceptions?
Is there a connection between futures and exceptions? async-await looks very similar to throw-catch.
1
vote
3answers
104 views
Where should PDOExceptions be dealt with?
I wrote a database wrapper class to help with queries and I'm trying to figure the best way to implement try-catch blocks.
In my database class, I have a helper function;
public function ...
2
votes
1answer
34 views
Storing exception information as a member variable for query later, bad practice? [duplicate]
I looking at the best way to handle exceptions, the answer to this question may be to handle the exception in a different place or to not handle to exception at all but to control the flow of the ...
4
votes
2answers
118 views
Strategies to analyze collected exceptions
We want to add error feedback to our application. I had a look at existing solutions (e.g. raygun.io), but these work "in the cloud", which is a no-go for us:
most installations of our application ...
1
vote
1answer
236 views
Why would we need to rollback twice before closing in a finally block?
I'm trying to implement the change in database connection closing suggested in this question's answers. More than once, I've come across this block of code at the end of my try blocks:
try {
...
4
votes
2answers
417 views
Best practice to handle POST with array of objects if at least one object raise an Exception
I want to POST an array of objects and make an insertion in database concerning each of them.
What is the best practice if one object does not conform and raise an Exception? (cancel all transactions ...
1
vote
3answers
118 views
Is an application supposed to recover from a exception thrown in PHP?
What if the programmer uses Exceptions for debugging? Would it be better in that case to just report the failure and immediately interrupt the script since ideally all bugs should be fixed radically?
...
7
votes
3answers
1k views
Is there an issue with closing our database connections in the “Finally” block of a Try statement?
I'm doing some refactoring for our application, and trying to reduce the number of issues reported in our ISO Scan (a static code analysis tool based on HP Fortify). Right now, what I'm trying to ...
0
votes
1answer
106 views
Code Inside Catch Block
This question is related to both of these questions - Efficient try / catch block usage? and Dealing with error in data - Idempotent approach.
When I encounter a void while reading a GIS data file I ...
3
votes
2answers
364 views
Best strategy to find the root cause when exception is swallowed by 3rd party
I am sure we have all run into a scenario where a 3rd part API complains with an incomplete stack trace. In essence the error handling in the 3rd party API does something like this,
catch ...
5
votes
7answers
2k views
Why have many programmers moved to using exception handling for input or output? [closed]
Why have many programmers moved to using exception handling for input or output? For these programmers, what is the motivation behind this decision?
2
votes
3answers
172 views
Extended usage of an exception
I'm in the process of building a routing system for learning purposes and have encountered an issue which I think is a bit in the grey area of best practices. Can you guys help me decide if this is ...
-1
votes
1answer
183 views
Should i avoid FaultException for Custom Validation Error messages to client [duplicate]
We are as a team working on a project which currently using WCF as in between client and server.
All business rules are written on managers classes which are used by service so its means no ...
0
votes
1answer
93 views
Pass by value result with exceptions [closed]
I have a doubt with the pass-by-value-result method. As far as I understood, it passess the value of the parameter to the function, and then get the result as the function ends. But what happens with ...
178
votes
9answers
13k views
Why do many exception messages not contain useful details?
It seems there is a certain amount of agreement that exception messages should contain useful details.
Why is it that many common exceptions from system components do not contain useful details?
A ...