Skip to main content

All Questions

0 votes
3 answers
5k views

Is throwing custom exceptions from private methods OK?

(I moved this question here, as StackExchange fits better, originally I posted it on StackOverflow.) This is not a question about a particular piece of code, rather I ask what is the right design ...
gai-jin's user avatar
  • 131
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 ...
Dennis's user avatar
  • 8,257
0 votes
1 answer
2k views

How to output exception messages in GUI applications in order to decouple application code to GUI code?

I want to make GUI applications such that the non-GUI code is independent from the GUI one (let's say I'll use Java 8 and Swing for example). The goal is that I could hypothetically change the GUI ...
Fabio Nardelli's user avatar
4 votes
2 answers
1k views

Verifying Parameters in Constructor or Service

I was reading on this SO page about when to check parameters when constructing an object. The accepted answer suggests throwing the exception from the constructor so that an invalid object cannot be ...
user avatar
3 votes
2 answers
743 views

Exception indicating implementation error

Problem I wonder what best practices are to indicate implementation errors detected at runtime. For example, if you write the following method (in Java): public void doSth(int i) { try { ...
user905686's user avatar
9 votes
4 answers
6k views

Should Exceptions Be Expressed on the Domain Model?

Let's say that we have a class PersonName and we throw an exception when some one try to create a instance of PersonName passing an invalid name to the constructor. Should the exception ...
Lucas Piske's user avatar
2 votes
2 answers
1k views

Handling exception types according to the current "layer" of appplication

Imagine this simple application use case, say, for fetching data from outisde of the app. These steps represent the "depth" of the layers, from top to bottom. UI touch event ViewModel handles said ...
Gil Sand's user avatar
  • 2,193
1 vote
2 answers
279 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 ...
Rolch2015's user avatar
  • 137
9 votes
3 answers
2k 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 ...
GregRos's user avatar
  • 1,763
2 votes
4 answers
1k 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 fetchAll($...
Eric's user avatar
  • 143
1 vote
2 answers
2k views

Smells in exception handling: how to separate between public and internal exceptions?

During the development of a small web API, we decided to separate internal exceptions from public exceptions. Public exceptions are HTTP exceptions, that translate into HTTP responses with proper ...
Klaus S.'s user avatar
  • 113
47 votes
11 answers
11k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
Mikayla Maki's user avatar
0 votes
2 answers
305 views

Expected error handling

Let's say I have a social media website. On this website, users can upload several pieces of information about themselves, including their phone number. To implement this, I have a class called ...
Mikayla Maki's user avatar
4 votes
2 answers
256 views

Is it an acceptable practice to Get a property, that involve parsing binary, that might throw an exception?

I have a property that is loaded lazily, any time after the ctor is called. It is possible that the binary that my property relies on is invalid. If invalid I might have to throw an exception. ...
makerofthings7's user avatar
3 votes
3 answers
2k views

Does Exception Handling Violates "Program to Abstraction"? [duplicate]

I am talking based on experience with Java and C#. I do not know if other language have different exception handling implementation. In order to achieve loose coupling, we need our code being ...
Fendy's user avatar
  • 196

15 30 50 per page