All Questions
Tagged with exceptions object-oriented-design
12 questions
0
votes
2
answers
322
views
Is it bad to use checked exceptions as API response?
Consider the following code:
public class User {
private String password;
public void changePassword( String oldPassword,
String newPassword) throws ...
3
votes
7
answers
854
views
Should a base class take responsibility for wrapping incorrectly thrown exceptions that are part of the API documentation? [closed]
It is a common approach to use specialized exception types to indicate exceptional results of a method. These exception types are not considered to indicate a programming flaw, but, as I pointed out, ...
3
votes
6
answers
164
views
How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?
Consider class Crate that is a value object. Crate represents a valid 3-dimensional box.
In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
11
votes
2
answers
23k
views
Where would you handle exceptions: controller, service, repository?
I have been having this dilemma from time to time whenever I have to design or start a new project from scratch.
I particularly like how Spring framework is organised in terms of classic software ...
51
votes
4
answers
18k
views
Exception propagation: When should I catch exceptions?
MethodA calls an MethodB which in turn calls MethodC.
There is NO exception handling in MethodB or MethodC. But there is exception handling in MethodA.
In MethodC an exception occurs.
Now, that ...
65
votes
12
answers
13k
views
Having a flag to indicate if we should throw errors
I recently started working at a place with some much older developers (around 50+ years old). They have worked on critical applications dealing with aviation where the system could not go down. As a ...
3
votes
3
answers
174
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 ...
6
votes
1
answer
1k
views
Should I always throw the most specific or should I try to generalize exception types?
Say you normally have FooException.
/**
* @throw FooException If Foo is invalid for searching.
*/
public bool exists(Foo a)
But at some point you need to have two more specific exceptions for Foo.
...
12
votes
1
answer
4k
views
When should I subclass an exception in Python?
In my code there are about seven places where I raise an exception. All of these exceptions are treated the same: print an error to log file, return software state to default and exit.
During code ...
8
votes
1
answer
3k
views
When to declare @throws with a Scala annotation - abstract parent or concrete implementation?
In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my ...
2
votes
1
answer
1k
views
Should we encapsulate everything in a try{} block in a Try object?
Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical?
class DBConnectTry extends Try {
TryResponse response[] attempt(TryObject o[...