Exception handling is the process of responding to the occurrence of anomalous or exceptional conditions requiring special processing – often changing the normal flow of program execution.

learn more… | top users | synonyms

3
votes
3answers
91 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 ...
3
votes
2answers
53 views

Handling exceptions in a loop without breaking the loop (try to process all members)

Scenario: I have a loop that iterates over an Array of COM objects and does some work using them. My fear, working with COM objects, is that some exception will creep up (possibly on another ...
3
votes
4answers
131 views

Design strategy for wrapping exceptions

I'm implementing a type of Repository for a framework/library that has (roughly) the following: public interface FooRepository { boolean contains(String id); Foo fetch(String id); void ...
1
vote
2answers
52 views

Is it valid to expect/throw an exception using a custom caching system?

Imagine some code like the following: class Cache { private Map<String, String> values = new HashMap<String, String>(); public String getFromCache(String key) { if ...
3
votes
3answers
125 views

Returning a Flag Indicating Success

Whenever I'm writing code, I always stub out my methods like this (not necessarily using generics): public T MyMethod() { T result = default(T); // or null return result; } This always ...
2
votes
2answers
66 views

Try Catch and Flow Control dilemma

I am aware that doing Flow Control on a program using a try-catch block is bad practice, but I can't see how to do it in another way when the error caught needs a redirection of the code's execution. ...
3
votes
1answer
63 views

Connection between futures and exceptions?

Is there a connection between futures and exceptions? async-await looks very similar to throw-catch.
1
vote
3answers
82 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 ...
2
votes
1answer
30 views

Storing exception information as a member variable for query later, bad practice? [duplicate]

I looking at the best way to handle exceptions, the answer to this question may be to handle the exception in a different place or to not handle to exception at all but to control the flow of the ...
1
vote
1answer
195 views

Why would we need to rollback twice before closing in a finally block?

I'm trying to implement the change in database connection closing suggested in this question's answers. More than once, I've come across this block of code at the end of my try blocks: try { ...
7
votes
3answers
1k views

Is there an issue with closing our database connections in the “Finally” block of a Try statement?

I'm doing some refactoring for our application, and trying to reduce the number of issues reported in our ISO Scan (a static code analysis tool based on HP Fortify). Right now, what I'm trying to ...
0
votes
1answer
76 views

Code Inside Catch Block

This question is related to both of these questions - Efficient try / catch block usage? and Dealing with error in data - Idempotent approach. When I encounter a void while reading a GIS data file I ...
3
votes
2answers
195 views

Best strategy to find the root cause when exception is swallowed by 3rd party

I am sure we have all run into a scenario where a 3rd part API complains with an incomplete stack trace. In essence the error handling in the 3rd party API does something like this, catch ...
5
votes
7answers
2k views

Why have many programmers moved to using exception handling for input or output? [closed]

Why have many programmers moved to using exception handling for input or output? For these programmers, what is the motivation behind this decision?
0
votes
1answer
79 views

Pass by value result with exceptions [closed]

I have a doubt with the pass-by-value-result method. As far as I understood, it passess the value of the parameter to the function, and then get the result as the function ends. But what happens with ...
1
vote
1answer
118 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
90 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
81 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 ...
3
votes
1answer
58 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
68 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
120 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
413 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
166 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
292 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
246 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
359 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
54 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) ...
23
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
146 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
154 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
188 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
143 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
211 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 ...
1
vote
3answers
127 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
111 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 ...
8
votes
2answers
642 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
82 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
77 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
140 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
309 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/. ...
6
votes
3answers
2k 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
729 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
500 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 ...
24
votes
5answers
6k 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
85 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
278 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
130 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
235 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 ...
2
votes
1answer
448 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
58 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 ...