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

0
votes
1answer
60 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
114 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
1k 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
74 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
112 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
50 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
67 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
49 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
52 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
99 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
269 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
143 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
233 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
215 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
258 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
48 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
127 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
127 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
184 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
125 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
171 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
110 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
103 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
619 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
74 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
71 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
125 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
232 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/. ...
4
votes
3answers
1k 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
627 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
497 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 ...
21
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
80 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
242 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
128 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
194 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
349 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
55 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
305 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
276 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
212 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
41 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
325 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
231 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
757 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
1answer
415 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
220 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
224 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
86 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 ...