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

3
votes
0answers
119 views

Purposely raising exceptions to use catch [migrated]

For a typical if...else wrapped with exception handling, is something like the following example a recommended practice to avoid code duplication? ...
0
votes
0answers
5 views

A middleware with process exception never called [migrated]

I have this middelware which is suppose to catch 500/400 exceptions and deal with them. But it never gets called. I've put it in the beginning and end of the ...
6
votes
2answers
68 views

Searching for files in a specified directory

I am currently writing a program that allows me to search for files in a user-specified directory. My current code is as follows: ...
2
votes
2answers
40 views

Java ClassNotFoundException Handling

Is there a better way to handle this ClassNotFoundException ? ...
1
vote
1answer
34 views

Compute logistic regression on tweet objects

Is my approach good to naming variables and exception handling? I would like to make this code more robust and maintainable. I need advice on exception handling, var naming and comments. ...
0
votes
1answer
24 views

Class for connecting to mongodb databases and return collection object

This code connects to a mongodb database and returns collection objects. I am concerned about the exception handling, variable names and comments. ...
3
votes
2answers
80 views

Check quotient and division by zero [closed]

Please evaluate this code and tell me if it is standard C++ coding: ...
5
votes
3answers
104 views

StoredErrorWriter

Functionality that overwrite standard error message with trace to user friendly message with error number stored in DB. Not yet completed some stuff with trx... Please review this. DB table: ...
0
votes
1answer
62 views

Exception Handling with `instanceOf` rather than `catch` [closed]

Would there be any reason to use the following code? ...
7
votes
1answer
446 views

Dividing 2 numbers

The problem is to input, divide 2 ints and display the result. Please, review my program. It worth noting, I've intentionally used ...
3
votes
2answers
36 views

How to reformat this code so I don't use 'Exit Try' and 'Exit For'?

I use SonarQube to help me try and become a better programmer to program along with 'best-practice' standards. There are business rules when a user is submitting data they enter in a datagridview ...
5
votes
2answers
44 views

Proper action when a Java program fails

I have a program that has to initialize a few big things (connect to a few databases, parse some XML) and without the initialization being successful the program would not be able to continue. Right ...
5
votes
3answers
445 views

Should this be written with exception handling instead of nested if-thens?

I have a function that iterates through a list of file updates, and for each file, if updates are needed, download the file from the server, make the updates, and upload the updated version. Each ...
5
votes
3answers
117 views

How to chain exceptions?

I have some function like: ...
4
votes
1answer
66 views

Simple helper method for JUnit3 tests

In JUnit 3, I cannot tell JUnit what type of exception is expected. In JUnit 4, the ...
7
votes
3answers
178 views

Simple MPG calculator in Python

I am a self taught coder taking a Programming Fundamentals class to work towards a degree. It's based on Python, which I'm not as familiar with as other languages. I added error handling like I would ...
20
votes
3answers
1k views

Java method - levels of abstraction

In his Clean Code book, Robert C. Martin states that functions should do only one thing and one should not mix different levels of abstraction. So I started wondering whether the code below meets ...
3
votes
1answer
75 views

Throw an exception to control the flow of code execution

There is a recommendation not to use an Exception to control the flow of execution. This gives me a reason for doubt when I do something like this: ...
5
votes
1answer
147 views

Code to construct a complete graph

I have tried to design a class for a complete graph. Needless to say, disadvantages of my current solution are very visible: dependent inputs have led to verification headaches. In this code we ...
3
votes
1answer
39 views

Passing around Connection

I have a myCon=getUnusedConnection() method that gets a connection from Connection pool. I also have a ...
3
votes
1answer
154 views

Is there any way to make this function, which takes char*, exception-proof?

I should preface this question by saying that I'm a Java programmer working on my first C++ application, so perhaps there are certain obvious things I don't know. Some background on the problem: Our ...
1
vote
2answers
97 views

What's better: return null or handle the Exception?

I'm in doubts what approach to take here, please have a look on the code below: ...
2
votes
1answer
68 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 ...
7
votes
3answers
126 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
135 views

Rethrowing exception just as an information

I have something like that: 1) My custom exception class ...
2
votes
1answer
109 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. ...
1
vote
1answer
112 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 ...
1
vote
1answer
78 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
135 views
3
votes
2answers
571 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 ...
5
votes
1answer
842 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: ...
10
votes
3answers
788 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
395 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 ...
1
vote
2answers
143 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 ...
2
votes
1answer
290 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
175 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
55 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 ...
5
votes
1answer
349 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: ...
4
votes
2answers
259 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
105 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
581 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
55 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 ...
8
votes
5answers
418 views
1
vote
1answer
58 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: ...
3
votes
2answers
64 views

Exceptions for control flow

I just wrote the following javascript (jQeury loaded): ...
1
vote
1answer
972 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 ...
2
votes
2answers
86 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: ...
2
votes
2answers
138 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() ...
4
votes
3answers
255 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
90 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 ...