An exception is an occurrence in an application process that requires deviation from the program's normal flow.
2
votes
0answers
54 views
Throwing an exception from within a constructor of an exception?
As I was TDD-ing some code, it occurred to me that one of my typed exceptions could potentially throw a NullReferenceException while creating its error message.
Here's the constructor for the typed ...
3
votes
2answers
98 views
Is an attempt to create a duplicate resource, e.g. a user, worthy of throwing an Exception?
Say I have an REST API for creating users in an application. The request goes to a controller, which marshals the request data into a domain object, and passes it to a service to create a user.
Now, ...
2
votes
0answers
43 views
Design interfaces with annotated exceptions, but reduce the need for exception wrapping / re-branding?
I am designing a library with a bunch of interfaces with annotated exceptions. (The example is in (pseudo)PHP, but I am sure one could do something equivalent in Java or other.)
For now, the ...
2
votes
2answers
221 views
Error handling in C++
So, in the recent weeks I delved into C++ programming, and I programmed some things in SDL. Doing so, you always have to deal with a lot of (ugly) C++ code, which looks more like C than C++.
One thing ...
3
votes
4answers
239 views
Exception treatment with/without recursion
I've entered in an argument with a fellow colleague about a piece of code. While he thinks that it is ok, I don't. But I don't have any more arguments than that calling the same method (recursion) in ...
38
votes
8answers
3k views
Should I throw an exception in case of a meaningful value outside of the range or handle it myself?
I have written a struct that represents latitude/longitude coordinates. Their values range from -180 to 180 for longtitudes and 90 to -90 for lattitudes.
If a user of that struct gives me a value ...
0
votes
1answer
64 views
What is considered best practice for custom exception classes?
Python has many strong conventions but I'm unclear on how best to manage exceptions for my module. I know it's generally good practice to define a custom exception for your module. E.g.:
class ...
1
vote
1answer
47 views
How to find the cause of an exception in async code
I often see myself trying to follow my own code to find out where the exception came from.
The typical example is when some parsing fails, and I catch the execption. Then I spend a ridiculous amount ...
0
votes
0answers
50 views
Is Shiro's use of Auth Exceptions an example of control flow? [duplicate]
In Java/OOP-land, it is a well established anti-pattern to use exceptions for control flow.
Apache Shiro is one of the standard Java security frameworks. When using Shiro, especially when ...
11
votes
2answers
2k views
Is using Exceptions at the highest level of a program considered bad practice? [duplicate]
I have seen programs using this strategy and I have also seen posts considering this bad practice. However, the posts considering this bad practice have been written in c# or some other programming ...
25
votes
7answers
2k views
Should a C++ program catch all exceptions and prevent exceptions from bubbling up past main()?
I was once advised that a C++ program should ultimately catch all exceptions. The reasoning given at the time was essentially that programs which allow exceptions to bubble up outside of main() enter ...
1
vote
1answer
75 views
Does exception handling belong at the lowest level of the runtime?
I'm designing a fairly simplistic stack-based programming language, and implementing it in Python. (no link, because it's not fully implemented yet.)
The language itself is essentially intended to be ...
1
vote
4answers
185 views
Handling exceptions I don't know about
When I work with handling exceptions, I notice that I often have to deal with the ones I had no idea about. Especially it is noticeable when I program a method that grabs data from web. An error may ...
3
votes
1answer
139 views
what happens at Java interpreter level when IncompatibleClassChangeError is thrown?
I am a noob at JVM internals.
Can someone explain what happens at Java interpreter level when IncompatibleClassChangeError is thrown?
I am facing an issue similar to the one described here: ...
0
votes
1answer
76 views
How can you catch all index out of range errors in python?
Our program does these kinds of operations hundreds of times for many different variables and lists, then uses them throughout the program:
variable = values[5]
The list values are coming from the ...
1
vote
2answers
68 views
Should a client check for persisted item existence before modifying it?
I'm developing a MVC Web application with a REST interface.
The REST controller performs actions on persisted items through a service class, which translates exceptions coming from the persistence ...
3
votes
3answers
158 views
Are exceptions only for handling errors?
I have a script that throws exceptions when something goes wrong. However, for the purposes of testing I also want to capture specific points although I'm not sure whether they would be deemed errors ...
1
vote
2answers
32 views
Exception Handling for class attributes in setters and constructors [closed]
I would like to discuss a question about best practices regarding exception handling (e.g. in Java). Normally, when setting the attributes of a class, I check the arguments in the setters for ...
-4
votes
5answers
241 views
Differences between `throw` and `throw new` and exactly how exceptions “bubble up” [closed]
Can someone please explain the differences in C# between:
throw
throw new
and exactly how exceptions "bubble up" as I've heard they do?
In my daily job, I've used just try/catch to mostly ...
-2
votes
1answer
41 views
Convention for exception argument order [closed]
Just a quick question about a design pattern for creating custom exceptions. The question is more about the order of parameters. If you can specify more data in the exception, should the parameter for ...
12
votes
6answers
335 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
194 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 ...
20
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 ...
7
votes
2answers
1k 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
110 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
41 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
566 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
160 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
89 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
365 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
145 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
80 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
71 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
394 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
79 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
136 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
73 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
119 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
92 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
212 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
211 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
323 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
307 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
137 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
339 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
389 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
115 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
153 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
185 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 ...