The exception-handling tag has no wiki summary.
3
votes
4answers
353 views
Java - Is it possible/good idea to reduce chance of crashing by catching Error?
I have a class the implements A which will run a certain method of class B. There is a requirement that this A should never crash when running this operation (which is not possible, right?).
To ...
6
votes
4answers
252 views
Why design a modern language without an exception-handling mechanism?
Many modern languages provide rich exception handling features, but Apple's Swift programming language does not provide an exception handling mechanism.
Steeped in exceptions as I am, I'm having ...
1
vote
3answers
64 views
Logging instance information in Exceptions
During development on a large existing codebase I've started to capture variable values in my Exception logging. For example:
public int Foo(int a, int b)
{
int returnInt;
try{
returnInt ...
1
vote
3answers
124 views
Null checking whilst navigating object hierarchies
I had to implement some code which traversed a small object hierarchy to fetch a value and display it in a TextView object (this is Android / Java). I had to do this 6 times to populate 6 TextViews ...
2
votes
1answer
119 views
RefactorException: Good idea or bad idea?
When I'm doing large scale refactors I'm often commenting out the contents of methods and using NotImplementedExceptions for stuff that I still need to refactor. Problem is that this is interfering ...
0
votes
2answers
71 views
Logging Exception in multi-tier application
I'm building a multi-tier enterprise application using Spring. I have different layers: Controller, Business and Provider. Within the application I've built a custom error handling mini-framework that ...
1
vote
1answer
100 views
Why is Throwable initCause designed to be called only once?
I find it really odd that the initCause method of Java's Throwable class can only be called once, or even not at all (if the constructor accepting a Throwable was used). This makes exception chaining ...
2
votes
2answers
47 views
How to ensure the success of processes after a deadlock exception occurs?
No matter the programming language is and whatever the database is, the concept should be the same:
I have 2 threads, each locking some database entities and inserting new data in database.
Let's ...
3
votes
1answer
124 views
Checked vs unchecked exception when validating documents in this service
I have a service that allow users to add dynamic content to a repository. So basically I have a generic Document class that contains a list of property for that specific object depending on what type ...
3
votes
1answer
173 views
Java-Like 'throws'-information in method signature C#
From Java I know that the signatures of methods that can throw exceptions contain a throws block, that contains the Exception(s) that might be thrown.
In C# there is no such thing and it is also not ...
3
votes
4answers
201 views
How much data should exceptions hold?
Almost all the exceptions I have ever written have been very lightweight, containing a String message and optionally a throwable. In some situations I have included some application specific enum or ...
1
vote
0answers
30 views
Multiple handlers of an exception, and handling exceptions in the UI
Related to: Is onError handler better than exceptions?
Premise
I am writing a piece of library code that performs certain tasks, to separate concerns, we decided it should not write to a log or ...
2
votes
2answers
98 views
What kind of exception to ask for out of range arguments?
What type of exception should I throw?
I have a console class which describes rectangle of cells which a user can index by passing in a coordinate:
width, height = 80, 25
console = ...
4
votes
4answers
223 views
Is it OK to let invalid arguments slip to another method?
For example lets take this method:
public List<string[]> ReadAll(int listCapacity)
{
List<string[]> list = new List<string[]>(listCapacity);
while (Read())
{
...
0
votes
2answers
184 views
IllegalStateException vs. IllegalArgumentException
In have written a function which expects the caller to pass in a configuration file like XML. Then I parse this given file and extract something which i then return.
In this function (at least) two ...
0
votes
0answers
69 views
Using Statement lambda in exception handling
Following is a code snippet from MVP Win Forms application and this explanation would be helpful when answering the questions.
My DAL doesn't handle exceptions and it will be propagated up to the ...
1
vote
1answer
88 views
Exception handling in WIn Forms application
When handling exceptions for example in a method in my presentation logic, is it ok to catch all possible exceptions in a one catch block as follows if the only purpose here is alerting the user.
...
1
vote
1answer
94 views
DAL Exception handling in a MVP application
In a MVP win forms application I'm handling exceptions as follows in DAL.
Since the user messaging is not a responsibility of DAL, I want to move it in to my Presentation class.
Could you show me a ...
0
votes
0answers
82 views
How to void checked exceptions in Java? [duplicate]
I consider checked exception for a design mistake in the Java language. They lead to leaky abstractions and a lot of clutter in the code. It seems that they force the programmer to handle exceptions ...
2
votes
1answer
91 views
How to present domain model exceptions thrown through validation
In domain model of my web application I've an entity Foo which can be created only by a pojo FooBean: Foo.newInstance(FooBean fooBean) (Might have been better a Builder-pattern.)
In the factory ...
10
votes
6answers
1k views
Should you throw an exception if a method's input values are out of range? [duplicate]
Should you throw an exception if a method's input values are out of range? eg
//no imaginary numbers
public int MySquareRoot(int x)
{
if (x<0)
{
throw new ...
0
votes
1answer
155 views
Is ok to throw exception in normal code path which eliminate a possible programmer error? [duplicate]
I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception.
But what happen ...
11
votes
6answers
620 views
alternatives to nested try-catches for fallbacks
I have a situation where I am trying to retrieve an object. If the lookup fails I have several fallbacks in place, each of which may fail. So the code looks like:
try {
return ...
1
vote
3answers
233 views
Exception when logging exception: is it correct to ignore them?
My question is specific to php, but i think it can be useful in other languages.
I log into a table all the exception a code can throw:
try{
//Some code
} catch (Exception $e) {
$log = new ...
10
votes
4answers
365 views
Purposely raising exceptions to use catch
For a typical if...else wrapped with exception handling, is something like the following example a recommended practice to avoid code duplication?
try
{
if (GetDataFromServer())
{
...
14
votes
1answer
872 views
Is it fine to make a default constructor unusable?
Specifically asking about the default constructor
Given that the constructor initializes all the data for an object, if I create a class that can't be used without proper initialization, is it not ...
3
votes
4answers
311 views
Should exceptions do things other than tell the user something went wrong?
I created a general class that accepts a string when it is constructed, and it spits out that string when a user calls what(). This is all it does; on throw, it returns the initializing string.
...
1
vote
1answer
54 views
Partial recovery from an Exception [duplicate]
I have seen Exception Handling blocks that they were throwing the recently caught Exception in the catch block. Something like:
} catch ( Exception $e ) {
// Do some recovery here
...
56
votes
8answers
6k views
Exceptions: Why throw early, why catch late?
There are many well-known best practices about exception handling in isolation. I also know the do and don'ts very well, but I search for a best practices or patterns in larger environments, ...
3
votes
4answers
279 views
Using configuration to determine whether to handle exception or bubble it up
On a side project I'm working on I came up with a way of handling exceptions that's adjustable by configuration. So a try/catch block might look like this:
try
{
fileHelper.MoveFile(file, ...
18
votes
2answers
1k views
Workaround for Java checked exceptions
I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
3
votes
2answers
124 views
Inform caller or just let them deal with exception?
I'm not sure how to proceed in the following situation.
say we have a function as so:
def runsATask(codes):
myDicts = [helperFunc(code) for code in codes]
for item in myDicts:
# some ...
12
votes
5answers
585 views
Exception handling in a program that needs to run 24/7
I have read that we should only catch exceptions that can be handled, which makes catching the base exception class (C# in this case) a bad idea (on top of other reasons). I am currently part of a ...
1
vote
2answers
134 views
Should I Aggregate Web API Errors?
The Situation
We are writing a REST API that performs validation up-front.
The code is written such that it tries to find as many errors as possible.
However, each error might correspond to a ...
7
votes
4answers
398 views
What are good ways of balancing informative exceptions and clean code?
With our public SDK, we tend to want to give very informative messages about why an exception occurs. For example:
if (interfaceInstance == null)
{
string errMsg = string.Format(
...
2
votes
1answer
121 views
How to handle when one user deletes the object while the other has it opened in edit mode in a webapp?
I am developing a CRUD type web application. It is a project management system having projects, milestones, tasks, employees etc. Each employee has his/her own account to login and view the system. ...
2
votes
1answer
127 views
I have a unexceptional exception. That is thrown by a API used in my project. Is it standard to log errors like these or handle them without logging [duplicate]
The API has a Throttle on the number of requests you can make. So we queue our requests in a local database and make as many requests as possible until the "Throttle exception" is thrown. Upon ...
5
votes
3answers
777 views
Authoritative sources for exception handling best practices [closed]
My work place suffers from a bad case of the Pokemon Exception Handling anti-pattern with constructs like the following splattered across the code base:
try {
...
} catch (Exception ex) {
// ...
2
votes
3answers
362 views
What code lays behind C++ exception?
In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data ...
2
votes
1answer
125 views
What are the guidelines for either throwing an exception or failing silently for nonvalid arguments? [duplicate]
If you look at XContainer.Add(object content) method you can see that id does not require content to be not null. It just does nothing in case of null.
However List.AddRange(IEnumerable collection) ...
2
votes
1answer
328 views
Why would one transform a checked exception to an unchecked exception? [duplicate]
My buddy told me today that some programmers transform a checked exception (e.g. EJBException, SQLException...) to an unchecked (RuntimeException?)
My buddy explained a call stack where if you change ...
1
vote
1answer
421 views
Can AspectJ or AOP in general be used to test exception handling?
I'm reading a book's chapter ("Controlled Exception Test" in "Testing Object-Oriented Testing") about testing exception handling in a running system (not at unit level). The conclusion is that it is ...
1
vote
2answers
138 views
Understanding unit testing for dynamically changing condition
I was trying to understand how to write unit tests for a few days now. I'm confused with following scenarios in the existing code.
In first function the max value changes depending on the object ...
2
votes
2answers
288 views
We need a custom strategy for collecting unhandled application exceptions. What are our options?
"Unhandled exception" term
In .NET Framework, unhandled exceptions are the exceptions which were not handled by the application itself, and result in a crash. In a case of a desktop application, it ...
37
votes
7answers
3k views
Are there legitimate reasons for returning exception objects instead of throwing them?
This question is intended to apply to any OO programming language that supports exception handling; I am using C# for illustrative purposes only.
Exceptions are usually intended to be raised when an ...
12
votes
5answers
868 views
Strengthening code with possibly useless exception handling
Is it a good practice to implement useless exception handling, just in case another part of the code is not coded correctly?
Basic example
A simple one, so I don't loose everybody :).
Let's say I'm ...
0
votes
1answer
134 views
Exception handling class: static or object-oriented?
I am working in a windows service (using VB.Net) for internal use of my department. When ever a certain type of exception (FooException for now on) is captured, I follow the same logic:
Log the ...
1
vote
3answers
218 views
Am I handling my exceptions in a sensible manner?
I'm still restructuring the code I have been given to update on my current work project, and I've come to the point where I'm looking at how the code handles an 'exceptional' input, that doesn't ...
0
votes
1answer
1k views
Exception Handling in Java web application
I know exception handling is a topic often discussed in the world of Java. I've read a few threads on here and SO as well.
...
1
vote
2answers
266 views
Wrapping specific checked exception in domain unchecked ones? [duplicate]
Uncle Bob says in Clean Code book that Unchecked Exceptions should be used. Now JDK has some checked exceptions: IOException, IllegalAccessException etc. which cannot be avoided.
In my application ...