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.
4
votes
1answer
53 views
Simple helper method for JUnit3 tests
In JUnit 3, I cannot tell JUnit what type of exception is expected. In JUnit 4, the declaration @Test(expected=NullPointerException.class) does it.
But, unfortunately in Android development, I can ...
7
votes
3answers
120 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
64 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:
public void initApplication(String input) {
...
5
votes
1answer
114 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
36 views
Passing around Connection
I have a myCon=getUnusedConnection() method that gets a connection from Connection pool. I also have a releaseConnection(myCon) method to release Connection to the pool after finishing using it.
When ...
3
votes
1answer
129 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
77 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:
private void processBarCodeResponse(String decodedQrCode) {
JSONObject jsonObject = ...
2
votes
1answer
53 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
110 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
109 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
83 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
1answer
73 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
61 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
128 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
188 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
464 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
433 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
202 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
98 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 ...
2
votes
1answer
206 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
160 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
49 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
0answers
235 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
...
4
votes
2answers
198 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
91 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
327 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
50 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
403 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
55 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
...
3
votes
2answers
61 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
617 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
67 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
131 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
210 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
87 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
552 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
276 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
443 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
174 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
415 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 ...
8
votes
2answers
294 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 ...
2
votes
1answer
340 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
192 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
180 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 ...
10
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
6k 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
136 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
413 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
1k 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 ...