Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution.

learn more… | top users | synonyms

2
votes
1answer
48 views

Review of approach to inheriting from std::exception [closed]

I would like a review and recommendations for improvement of my approach to resuing std::exception. Just a quick justification for the four constructor arguments: I want to force myself to always ...
6
votes
3answers
104 views

Exceptions handling, what would you do?

I know that there are several ways to handle exceptions and probably a good way is to keep the handling consistently and use the pattern which feels comfortable for himself, but I would like to get ...
3
votes
1answer
92 views

Rethrowing exception just as an information

I have something like that: 1) My custom exception class public class SolvableException extends RuntimeException { protected boolean solved = false; public SolvableException(String ...
2
votes
1answer
61 views

Exception Handling Design

I am trying to design an exception hierarchy for logging errors. These logs will be used only by developers and not by users. This is a base class that I came up with. #ifndef TSTRING_TYPEDEF ...
1
vote
0answers
41 views

Exception based on std::exception but easy to modify and rethrow

I've looked at boost::exception and realized it is too advanced for my project, as my colleagues mostly have legacy C background. I do not need arbitrarily complex information in exception, just some ...
1
vote
1answer
42 views

How to refactor this importer to handle validation errors?

This is my importer to database from excel file. I would like to handle situations when any error raise. To not breaks whole import when one errors occurs. For example when there is duplicated record ...
3
votes
1answer
126 views

Compiler warning on unused exception…need to improve structure?

Consider the below: public int DoSomethingComplicated(ComplicatedObject input) { try { return input.Analyse(); } catch(CustomExceptionOne ex1) { throw; } ...
3
votes
2answers
99 views

Review of “is port in use?”

Review this code. It should return true if a port is in use, false if the port is not in use. Clarification : "In use" means that the port is already open ( and used by another application ); I'm ...
5
votes
1answer
165 views

Reducing cyclomatic complexity

I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches). Here is my code: public void myMethod(){ try{ // do something ...
9
votes
3answers
302 views

Try-catch inside while(true)

I have a situation in which a program, communicating over the network, can timeout or otherwise fail to establish a connection through no fault of my application or its user. If and when this happens, ...
1
vote
2answers
119 views

A better way of checking if index is out of bounds

For a simple project, I represent a two-dimensional grid as a one-dimensional array, with both row and column indices between 1 and gridHeight. When retrieving a cell from the grid, I first need to ...
1
vote
2answers
83 views

Exceptions to control data read flow

I previously posted a Reservoir-Sampling program, which was basically a test version of this one. This is an assignment. In the code below, I use RunTimeException to control when scanner finishes ...
1
vote
0answers
99 views

Managing Data access layer exceptions

I am developing a webapp using Spring MVC + Hibernate. I created a GenericDao class that implements basic data access methods, to be extended by all my concrete daos in the app. What I want advice or ...
5
votes
2answers
148 views

Object can throw exception on construction, but I don't want it to stop everything

I have a factory that loads configuration from an xml file, and uses the configuration to be able to create objects of an appropriate type with appropriate settings. My application does a number of ...
0
votes
1answer
44 views

Dealing with resource closure when rethrowing an exception

I would like a review and recommendations for improvement of the code below. I want to allow an exception to be handled by the caller, so I am rethrowing it. But I have resources to close. So I ...
2
votes
1answer
171 views

Yii exception usage

I've never used a framework before, so I wanted to see if this fairly simple scenario was done correctly or could be improved: public function actionCreate($id) { // Is request Ajax ...
3
votes
2answers
153 views

OOP Methods/Functions that can return a value or an exception

Introduction I'm currently working through a series of bugs in an application. Our application is written in C#/ASP.NET (on the server) and HTML/CSS/JavaScript (on the client). We are using ELMAH to ...
4
votes
1answer
77 views

Is brute force the accepted best practice for handling Excel COM 'busy' exceptions?

Following on from a question about handling-com-exceptions-busy-codes I would like to know if the following model is the accepted best practice of handling Excel COM busy messages when accessing the ...
3
votes
2answers
214 views

Tasks: exceptions and cancelation

I need to do a long running task. I've done this by executing a Task while there's a loading box on the UI. When an exception is thrown, I want to stop the task and show a msgbox to the user. If ...
3
votes
1answer
46 views

What changes, if any, are required to make the following Perl eval bullet proof?

eval { # here is put some code that may throw exception 1; # Why is the "1;" here ? } or do { my $error = $@; # Handle error. }; Does the following style protect against $@ not being ...
8
votes
5answers
384 views

Saving a contact and dealing with exceptions

try{save.Username = usernamedetails.Rows[0].ItemArray[0].ToString(); } catch{ save.Username = ""; } try { save.Firstname = dtdetails.Rows[0].ItemArray[1].ToString(); } catch { save.Firstname = ""; } ...
1
vote
1answer
53 views

Is 'try / finally' the best way for me to handle (and close) this long-running IMAP4 connection?

I'm writing a script to archive email messages from one IMAP folder to another. It looks, more or less, like the following. I've obfuscated about 30 lines unrelated to this question: import imaplib ...
1
vote
0answers
34 views

Exceptions for control flow

I just wrote the following javascript (jQeury loaded): var valid, ui; try { $.each(this._cache, function() { $.each(this, function() { $.each(this, function() { ...
1
vote
1answer
375 views

Accumulating inner exception messages

Say, there is a class with some methods, that have try catch blocks. I need to accumulate messages from all inner exceptions of generated exception and use throw new Exception(exceptionMessages). I ...
2
votes
2answers
60 views

Wrapping an Exception with context-management, using the with statement

Before I try to make this work, I wondered if anyone had tried this, whether it was a good idea or not, etc. I find myself doing this a lot: if some_result is None: try: raise ...
2
votes
2answers
125 views

What to do with the Exception when you fail to close() a resource?

I am happy to receive all recommendations for improvement. But below I am mostly interested in a review of my handling of the exception thrown by the close() method of RandomAccessFile. The ...
4
votes
3answers
177 views

Wrapping Exceptions

It doesn't happen often, but I sometimes come across cases where I miss Java's checked exceptions, especially in medium sized methods of about 30 odd lines that call outward. Often, the following ...
1
vote
3answers
75 views

When to catch/wrap an exception vs declaring that method throws exception

In the snippet below the three exceptions I declare in the throws clause are all thrown by BeanUtils.setProperty(), which is a third party library. Is letting these three exceptions "bubble upwards" ...
0
votes
1answer
347 views

Multi Threaded Error Logger

I am trying to design a class that will log errors to a text file, the application is using threads heavily so it may be that 2 errors that need to be written at the same time. I know there are 3rd ...
1
vote
2answers
190 views

Excel instances: release and kill

Please check my code below. I don't have any problems but I'm not aware how far the code will work, release and kill excel instances.. try { wBook = xCel.Workbooks.Open(excelfilepath); ...
4
votes
3answers
355 views

Handling optimistic concurrency violations

I'm trying to establish a concurrency violation verification in my SQL updates using C# and raw SQL. What I'm doing now is storing the TimeStamp value in a byte[] upon selection and before updating ...
4
votes
1answer
169 views

Is there a better way to test for the exception conditions?

This method assigns the value of a specified column in a DataRow to specified property in an object. I have 3 conditionals handling exceptions, and I want these conditions to throw exceptions. The ...
6
votes
2answers
365 views

Simplifying exception handling on Enumerators

I have a files search function that iterates over a given directory until a given depth is reached and returns the found files. I did this via the Enumerate methods of the Directory class and yield ...
6
votes
1answer
201 views

Get rid of pokemon exception handling

I wrote a productivity app for Android. It let's you switch system settings, like bluetooth, wifi, screen brightness, volumes, ringtones, mobile data, airplane mode, etc. Unfortunately I have ...
1
vote
1answer
265 views

Functional Exception handling with TryCatchFinally Statement helpers

Hello All, I wrote something to the effect of a try catch finally statement helper in functional style so that I can shorten much of the code I'm writing for my Service Layer that connects to a sql ...
3
votes
3answers
146 views

Reading image from jar

I am using this static method in my class IconManager to read an image from jar file. imagepath is a relative path to the image. This code works perfect. But I was told it is error-prone, because ...
4
votes
2answers
169 views

I there a better way to handle try in C#

I know that is generally expected that you should not swallow exceptions. In this code an Infragistic's UltraWinGrid is being configured. Is there a better way to handle the failed catch's are is this ...
9
votes
8answers
1k views

Replace strings in a file

I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to ...
6
votes
3answers
5k views

Recommended method to use a WCF service client and handling it's exceptions

I am new to WCF and need to work with another programmer's code. I am unsure of the way the WCF service client is used here : private void barButtonDocuments_ItemClick(object sender, ...
6
votes
1answer
125 views

Attempt at an implementation of a TextFile class

How can I improve this class that should represent a text file? Im trying to write a simple class to represent a text file - which one would think should be quite easy.. I don't intend to add all ...
8
votes
3answers
396 views

Exception handling, et al - How do I make this not “poor”?

I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions: Why is this error handling considered poor? How am I supposed to be doing it? ...
5
votes
1answer
999 views

Handling parsing failure in Scala without exceptions

I have a Scala (Play!) application that must get and parse some data in JSON from an external service. I want to be able to gently handle failure in the response format, but it is becoming messy. What ...
6
votes
2answers
455 views

Return inside try block

Is this return style acceptable? Would the code be more readable if I assigned the MonthDay.parse() return value to a variable and returned that variable on the last line? Also, is it a bad idea to ...
5
votes
3answers
441 views

Scala: a safer way to cut string

I want to get just the first line of a big string. Currently, here's how I do it: def getFirstParagraph(txt: String) = { val newLineIdx = txt.indexOf("\n") match { case i: Int if i > 0 ...
5
votes
3answers
276 views

Refactor this exception handling code

I am having difficulty deciding how to implement an exception handling strategy. I am using an observer pattern to allow "plugin" programmers to subscribe to Messages. These subscribers generally log ...
7
votes
4answers
355 views

Does this code follow standard conventions?

I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards. In ...
1
vote
2answers
169 views

Throwing the Exception But Using the Finally Block

Does this piece of code make sense? The idea is to throw any exceptions that may occur but always run the finally block to close the streams. private void streamToFile(HttpResponse transferResponse) ...
8
votes
3answers
615 views

When to catch a general exception

I have a class which throws alot of exceptions : try { mapper.writeValue(outStream, myVal); } catch (JsonGenerationException e) { e.printStackTrace(); } catch ...
2
votes
2answers
135 views

Add events dispatching for ActionScript framework Robotlegs

I have the following function in a Service class protected function writeToFile():void{ var destinationFile:File = File.applicationStorageDirectory.resolvePath(_newPath); var ...
4
votes
2answers
810 views

Encapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?

In an effort to reduce code duplication, I often use and have used this style to capture handling of exceptions on a boundary of an application: Given the following extension methods: public static ...