All Questions
Tagged with exception-handling or exceptions
642 questions
5
votes
1
answer
898
views
Is using Option#get really a bad idea here?
I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code:
Option#get is disabled - use Option#fold instead
While I do understand how get should often be avoided,...
4
votes
2
answers
312
views
What are common/best practices for frameworks handling standard third-party exceptions?
Amongst other things in my life, I'm writing a framework in PHP to manage a slew of common problems I come up against in every project I tackle. The framework is currently very data-centric, with the ...
11
votes
5
answers
2k
views
How to design exceptions
I'm struggling with a very simple question:
I'm now working on a server application, and I need to invent a hierarchy for the exceptions (some exceptions already exist, but a general framework is ...
-1
votes
3
answers
589
views
Reasoning behind custom class Exception
I am learning Python and when I learned that we can build Custom classes for exception, I got into a confusion of Why ?
for example1 :
class MyException(Exception):
def __init__(self, error):
...
-1
votes
1
answer
1k
views
Difference between Exception "Ducking" and "Swallowing"
I came across a tutorial which says this code is Exception Ducking
public class SomeClass {
void doTask() {
try {
//..Some Exception prone code
}
catch(Exception e) { }
}}
...
6
votes
8
answers
7k
views
Ignore exception when closing a resource such as a file?
From Effective Java 2e by Joshua Bloch,
An example of the sort of situation where it might be appropriate to ignore an
exception is when closing a FileInputStream. You haven’t changed the state of
...
24
votes
10
answers
6k
views
Parameter to control whether to throw an exception or return null - good practice?
I often come across methods/functions which have an additional boolean parameter which controls whether an exception is thrown on failure, or null is returned.
There are already discussions about ...
3
votes
2
answers
788
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 {
...
8
votes
2
answers
4k
views
Error handling and exceptions in a layered (or onion) architecture [closed]
Given an onion architecture, what are the advantages and disadvantages of throwing exceptions in the business logic (which is in the center of the onion) for invalid parameters provided by the user?
...
-1
votes
1
answer
351
views
Null Object and Exceptions
Do Special Case or Null Object design patterns still provide value when application behavior, not just object behavior has to change?
I was tasked with revisiting an old application and refactoring ...
1
vote
1
answer
127
views
What kind of exception of SPL is best suited for file exceptions?
When I use the Exception provided by the SPL the options are limited. So it's hard to pick which exception would be best suited to handle File exceptions.
I know the best scenario is to write my own ...
1
vote
2
answers
2k
views
Function that throws exceptions extending IllegalArgumentException
I have a try/catch block which looks like this :
try {
geoms.add(convertLineToGeom(ln));
} catch(IllegalArgumentException e) {
System.out.println("ligne n°" + counter + " : " + e.getMessage())...
1
vote
1
answer
227
views
Catching base Exception to preserve data integrity
I know that often catching all exceptions (C#: catch(Exception exception){...}) is deemed bad practice.
However, I believe that there are situations where it is perfectly reasonable to do it. For ...
1
vote
2
answers
275
views
Why are there non-catcheable exceptions?
I recently asked a question on SO where I was trying to understand how to catch an exception in a piece of code which runs indefinitely. I was initially expecting that
try:
...
-1
votes
1
answer
3k
views
Spring Exception Handling. Custom exception per Http status?
I'm just designing the exception handling for the REST interface on our Spring server.
As we will have multiple REST controllers, a central exception handling is desired. Spring offers the solution ...
-1
votes
1
answer
77
views
Handling RuntimeExceptions thrown from Services and Libraries
I am working on a ReST based service which calls other ReST based services and also deals with Persistence in a database. So a typical call might look like
Get some data from the database.
Make a call ...
11
votes
2
answers
4k
views
What should I do with implementation-specific exceptions?
Let's say I have an interface describing a simple service
public interface AccountService
{
public int getUserId(String userName) throws UserNotFoundException;
//...
}
I've written the ...
4
votes
2
answers
288
views
Design of multi-test function to validate a string
Assume that I wish to perform an action on a string (e.g., print the string) if, and only if, the string first passes several tests. The tests are diverse (and may even be complex functions themselves)...
33
votes
3
answers
6k
views
Error handling considerations
The problem:
Since long time, I am worried about the exceptions mechanism, because I feel it does not really resolve what it should.
CLAIM: There are long debates outside about this topic, and most ...
38
votes
4
answers
23k
views
Are exceptions for flow control best practice in Python?
I'm reading "Learning Python" and have come across the following:
User-defined exceptions can also signal nonerror conditions. For
instance, a search routine can be coded to raise an exception ...
2
votes
4
answers
774
views
Should exceptions not be thrown in Node.js?
I just started working on a new project and no one throws exceptions over here. I get that you shouldn't be doing that for asynchronous code, but it seems to be a valid way to do things for the ...
5
votes
4
answers
9k
views
How should state machines handle exceptions in actions?
State machines, for example UML state machines, statecharts or other finite state machines, allow actions to be executed when a state machine takes a transition between states or is within a state.
...
3
votes
2
answers
2k
views
Augment a thrown exception with some contextual information
The application this question is about is basically a transpiler which contains a lot of logic. The transpiler is written in C++ (which should not be much of relevance for this question), and it ...
10
votes
1
answer
750
views
Different kind of checked exceptions - Guarantee to only throw X
It is a widely held position that checked exceptions as implemented in Java are a bad idea. If you mark a method as throwing, calling code has to either catch the exception, or be marked as throwing, ...
0
votes
2
answers
185
views
Enteprise standard for Exception flow
What is the commonly accepted enterprise standard for Exception management?
Consider the project has three layer structure.
- Controller
- Service throws ServiceException
- Dao throws DaoException
...
3
votes
2
answers
341
views
Why does Java's getSystemResourceAsStream silently consume IOExceptions?
While trying to debug a weird issue where I knew an exception should have been thrown but was not, I found the following in the Java standard library's java.lang.ClassLoader class:
/**
* Open for ...
7
votes
2
answers
1k
views
Is it bad practice to have functions whose sole purpose is to throw errors?
I have the following situation.
I'm writing a c++ program where I have a function that checks a custom equivalence of two json objects. If the check fails, I don't want the entire program to stop (...
1
vote
2
answers
2k
views
How to handle passing a DAO object with custom exceptions in java?
I have my multi module maven project with the following structure:
+ parent
- pom.xml
+ model
- persistents
- dao
- model stuff...
- pom.xml
+ service
- services
- services ...
78
votes
14
answers
19k
views
Why is Arithmetic Overflow ignored?
Ever tried to sum up all numbers from 1 to 2,000,000 in your favorite programming language? The result is easy to calculate manually: 2,000,001,000,000, which some 900 times larger than the maximum ...
1
vote
5
answers
1k
views
Avoiding exceptions for performance optimization
In our code base, I see a lot of code like this
var error = ValidatePhoneNumber(userId, phoneNumber);
//if validation fails, return error
if(!string.IsNullOrEmpty(error))
{
return error;
}
If I ...
1
vote
4
answers
4k
views
Exceptions and libraries
I'm writing a library which will be a base for a turn-based battle system but i don't know what are the best practices for exception handling, has anybody some advice for me?
Should I catch every ...
4
votes
5
answers
3k
views
Is it better to have many specified exceptions or some general that are raised with specified description?
What is the better way to organize exception in a Python project? What is the right way to use exception description?
For example I have a function that parse email and return some data from it's ...
11
votes
2
answers
13k
views
REST: How to determine transient exceptions?
As I try to deal with the possibility of failure when I invoke RESTful endpoints or in general any HTTP endpoint I've been wondering if there is any standard or pattern in the HTTP specification or in ...
13
votes
4
answers
10k
views
How should I write a test for a pure method which doesn't return anything?
I have a bunch of classes which deal with validation of values. For instance, a RangeValidator class checks whether a value is within the specified range.
Every validator class contains two methods: ...
3
votes
6
answers
368
views
What to do with exceptions that arise from bugs?
There are cases where I don't know how to use exception handling. To make it clear, let me divide exceptions into two types:
exceptional cases that may happen occasionally, such as when you try to ...
0
votes
4
answers
5k
views
How to deal with IOException when file to be opened already checked for existence?
This is a specific question here, but I'm interested in the general "best practice" for similar situations as I'm new to Java.
Suppose I have Java code that needs to open a file (see below for code). ...
6
votes
2
answers
707
views
How do I create idiomatic error interfaces in Ruby?
I'm developing a Ruby on Rails app. The app contains a service wrapping an external REST API, called from a controller, with several possible error states. The current implementation returns the ...
3
votes
1
answer
1k
views
Exception Hierarchy and Use of What Message for Parsing Strings
I have a piece of code parsing a text file line by line. I have to goals: Testing the syntax of the text and extracting information of it. It is quite likely that syntax errors occur so I want to ...
7
votes
4
answers
429
views
Subtyping without adding state or behavior - Bad Practice?
Observation
There are many Exception subtypes that don't have any added state or behavior. For example, ClosedByInterruptException code.
Question
Why is subtyping without adding state or behavior "...
112
votes
13
answers
12k
views
Exception vs empty result set when the inputs are technically valid, but unsatisfiable
I'm developing a library intended for public release. It contains various methods for operating on sets of objects - generating, inspecting, partitioning and projecting the sets into new forms. In ...
5
votes
4
answers
2k
views
Why do some APIs simply throw Exception?
This year I started using several Third-Party-Libraries (all open source) and I noted that some throw exceptions in a proper way (i.e. declaring exactly which checked Exceptions can be thrown by a ...
4
votes
1
answer
140
views
How are asynchronous exception implemented?
What changes need to be made to a language/runtime if one wants to implement fully asynchronous exceptions (thrown from one thread to another, capable of interrupting pure computation without the need ...
24
votes
4
answers
12k
views
How should I provide additional information about an exception?
Everytime I need to provide additional information about an exception I wonder which way is actually the right way of doing this.
For the sake of this question I wrote an example. Let's assume there ...
33
votes
5
answers
4k
views
How can I create and enforce contracts for exceptions?
I'm trying to convince my team lead to allow using exceptions in C++ instead of returning a bool isSuccessful or an enum with the error code. However, I can't counter this criticism of his.
Consider ...
6
votes
2
answers
4k
views
What are the differences between software interrupts/exceptions
So I wanted to know the differences between these two. I know software interrupts are sometimes referred to as exceptions, which makes the differences between the two somewhat confusing. Asking this ...
1
vote
1
answer
546
views
Is a General Exception In Addition To Expected Exceptions Defensive or Unecessary?
I have read this and this and this: if my question misses the point in those answers, please point it out and we'll get this one deleted. These questions indicate that this may actually be a bad thing ...
5
votes
0
answers
134
views
Why exogenous exceptions? [duplicate]
So in a relatively famous blog post, Eric Lippert categorizes exceptions as lethal, vexing, bone-headed, and exogenous. He defines vexing exceptions as ones created by unfortunate design decisions and ...
2
votes
3
answers
2k
views
Benefit of throwing exceptions for null parameters
The codebase I work with has a certain pattern prevalent in all public methods, which goes like this:
public void UpdateUser(User userArg)
{
Framework.NullCheck(userArg);
var user = userDb....
3
votes
2
answers
3k
views
Why throw exception that is subclass of another exception also thrown?
Why do some Java methods throw exceptions that are subclasses of another exception that they also throw?
One example is org.apache.commons.httpclient.HttpClient.executeMethod(HttpMethod method). It ...
3
votes
1
answer
1k
views
Is it okay to use exception handling as exit conditions for a method? [duplicate]
So I've been programming for a few years mostly as an amateur/student, and I'm aware of the fact that using exceptions is generally frowned upon when used as a lack of consideration for input and just ...