The exception-handling tag has no wiki summary.
1
vote
1answer
106 views
Using exceptions as regular objects [duplicate]
I have views that handle different errors in my application. For example error 404, 403 and such, giving my errors a more user-friendly presentation. By assumption, they get passed in an exception, so ...
0
votes
1answer
36 views
proper exception handling (throwing/message) dll libary
I just wrote a dll library using vb.net. while testing, i got an error which i did not initially use a try-catch block. The code is
Try
'The first four bytes are for the Command
...
0
votes
2answers
54 views
How do I find out what type of exception I am supposed to raise?
I suppose this question is valid for any programming language that can handle (or at least throw) an exception. However I will stick to Python as an example.
The top 2 answers to the following ...
1
vote
0answers
20 views
How to handle Django get-single-instance-in-view pattern?
A lot of my Django views start a little bit like this:
try:
# here request.POST could also be request.GET or a captured URL parameter
MyModel.objects.get(user = request.user, some_attr = ...
0
votes
2answers
42 views
Catch unusual exceptions on production code for web apps
Lets say I have a web app, and despite my best testing efforts, several of the many thousands of people who uses it will find some way to generate an exception. Sure, I have error handling code for my ...
0
votes
1answer
88 views
Is there are any common pattern/practice to handle exception list (Java)? [closed]
Suppose I've got a sophisticated parser for something.
And a I don't want Throw Early/Fail-Fast strategy.
If I've got multiple problems, i want to have list of exceptions in my log file
because I want ...
4
votes
2answers
185 views
When to create a custom exception in C#
I'm writing a class to interface with a simple hardware device over a COM port. The device can configured to use various modes, so my class has a SetOperatingMode function, that takes in an enum of ...
1
vote
1answer
127 views
How to make sure that the destructor cannot throw an exception?
I know that we can specify the compiler that a function is not throwing an exception by using noexcept specifier but noxecept functions can still throw exceptions . So, how to prevent destructor from ...
4
votes
2answers
185 views
Exception versus return code in DAO pattern
After reading a lot about the abusive use of exceptions in Java and how you should let an exception bubble up through the different layers of an application, I've come to a point where I don't know ...
3
votes
5answers
154 views
Exception handling and 3rd party library
I'm currently having an issue with a 3rd party control library provider. They have an exception occulting culture that gets in the way of my general fail-fast approach when developing software.
An ...
0
votes
3answers
138 views
Convention for logging within nested try catch blocks
I've looked at this question but it doesn't really help solve my dilemma.
System 1 calls system 2 within a try catch, the method in system 2 has it's own try catch, which sadly handles an exception ...
0
votes
1answer
39 views
Exception handling scope when dealing with nested exceptions
Assume you have one object that has two methods which both throw different exceptions. These methods must be used together. For instance:
SqlCon{
static SqlCon connect(string user, string pass) ...
22
votes
11answers
5k views
Is the 'finally' portion of a 'try … catch … finally' construct even necessary?
Some languages (such as C++ and early versions of PHP) don't support the finally part of a try ... catch ... finally construct. Is finally ever necessary? Because the code in it always runs, why ...
1
vote
2answers
119 views
Is it a Good Practice to Catch All Exception? [duplicate]
The snippet below (in java) gives an example of my question.
try {
// code implementation here
}
} catch (Exception ex) {
}
...
2
votes
1answer
114 views
How to differentiate between exceptions coming from system and business logic?
I would like to differentiate between exceptions coming from business logic like
requested database record does not exist
attempt to store invalid business data (validation failed)
provided CSV file ...
3
votes
2answers
180 views
How to deal with historic exception specifications in maintained C++ code
Today, I discovered a few exception specifications in legacy code I've to maintain, when Cppcheck 1.68 ([Inconclusive] but correctly) pointed out that the specified exceptions are not handled in ...
0
votes
1answer
113 views
Where would be better to handle an exception?
Imagine I have the following DAO method:
public Employee getEmployeeById(Integer id){
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate());
String sql = ...
3
votes
2answers
139 views
Scala and exception handling [closed]
I am curious why exception handling is a topic often ignored in Scala. Is it the goal of the language (or the style) to not rely on exception handling except for external input/code?
I was hoping ...
0
votes
3answers
103 views
Coerce bad input or always crash early
The general consensus seems to favor the Crash Early approach, the most reputable source being the acclaimed Pragmatic Programmer book.
And while I understand and agree with the advice in many ...
0
votes
1answer
98 views
Replacing Throwing Exceptions with Notification in Validations
Martin Fowler recommends replacing exceptions with notifications when dealing with validations. Essentially, instead of throwing an exception, you append error messages to a Notification object that ...
7
votes
2answers
599 views
How should I handle logger failures?
In several of our company's applications, we use a custom logger. It's fairly robust, though we may replace it with something like NLog in the future. One of the logger's tasks is to log any ...
2
votes
1answer
72 views
Under which circumstances does it make sense to lose track of where an exception was thrown from?
Is there any valid reason why a catch block on a lower layer would throw back an exception caused by a higher, unknown layer using the following syntax:
throw ex;
... rather than:
throw;
... ?
...
0
votes
1answer
64 views
Advice needed on rethrowing an exception
Consider the following c# code:
public class ExceptionManager
{
public static void TreatException(Exception ex)
{
if (ShowAndContinue(ex))
// display a user-friendly ...
3
votes
1answer
121 views
Exceptions in ANSI C
Would it be possible to implement exception mechanism in pure ANSI C similar to the one used in popular OOP languages (with familiar try-catch-finally clauses)?
If yes then how?
I'm especially ...
1
vote
4answers
200 views
Java exception handling design
I am trying to design a simple exception handling strategy for web services middleware using some ideas from here: http://northconcepts.com/blog/2013/01/18/6-tips-to-improve-your-exception-handling/.
...
3
votes
3answers
847 views
Should service layer catch all dao exceptions and wrap them as service exceptions?
I have three layer Spring web app: dao, service and controllers. A controller never calls directly the dao, it does it through the service layer. Right now, most of the time if there is dao exception ...
1
vote
1answer
487 views
Exceptions: What to handle, what to throw
I have a custom configuration reader which performs various functions on top of .NET's CloudConfigurationManager and ConfigurationManager implementations, such as caching, type conversion, etc.
The ...
3
votes
4answers
492 views
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 ...
19
votes
5answers
4k 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
76 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
211 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
125 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
156 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
269 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
53 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
256 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
228 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
208 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 ...
2
votes
0answers
39 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
249 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
229 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())
{
...
1
vote
2answers
562 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 ...
1
vote
2answers
337 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
173 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
188 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
85 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
141 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
3k 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
204 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
890 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 ...