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

9
votes
4answers
1k views

Send email just once per day

I want to send an email just once per day. There is one button and any user can click that button. The email must not be sent twice. When the first user clicks the button, the email is sent. If ...
1
vote
1answer
33 views
1
vote
0answers
21 views

Pausing a SwingWorker with a Timer

I made a SwingWorker which is fetching tweets using the twitter4j API. The twitter API will allow 180 queries every 15 minutes, and then throw an exception with ...
7
votes
2answers
75 views

Exception handling for HTTP request timer

This method is used to check a URL and return the time it takes to check and the HTTP status code: ...
3
votes
1answer
47 views

Throwing an exception within a try/catch block in PHP

Is there a cleaner way to do this? ...
6
votes
2answers
58 views

Retry loop for asynchronous HTTP requests

I've got a method that needs to PUT data to a web API. Sometimes the connection fails, so I needed a way to do retries, but if the retries fail, I still need to capture the exception and re-throw it. ...
7
votes
4answers
1k views

Dice-rolling program

I am sort of new to programming. I would like to understand the code areas that are garbage and could be better written keeping the exact (if possible) behavior the code has now. ...
7
votes
3answers
348 views

Handling exceptions for providing log information while debugging

I am catching exceptions to provide better information for the logs to make debugging easier in production. I was wondering if this code follows best practices as I'm not really handling the error ...
3
votes
1answer
41 views

Selenium Java: errorRecovery

I have the following code to select an image using Selenium, only now I have added an errorRecovery. Is there is a better way to right the code in the ...
8
votes
3answers
66 views

Validation/error handling of user input values

This is a tiny learning program that lead to an interesting question: how can I best/most elegantly handle user entered numbers? This method works, fails cleanly, and reads well. It doesn't apply to ...
5
votes
3answers
746 views

Class for catching error and logging

I often write something like this in my code: ...
2
votes
1answer
89 views

Simple Operations Calculator

I'm practicing Swing effects. Everything works but for some reason I get a ton of error messages in the command prompt when the fields are empty, despite my attempt to add some exception handling ...
1
vote
1answer
74 views

Is this acceptable usage of try/catch and database transactions?

I am using try/catch syntax in combination with a database transaction to (hopefully) prevent partial registrations. I am ...
4
votes
1answer
51 views

Improvements to nsiZipReader and nsIScriptableInputStream

I wrote this code to list contents of an XPI file and then read the contents in it. I was thinking areas of improvment: I put the zr.open in the ...
2
votes
2answers
46 views

Branching with multiple Try

I have a series of four method calls that all return Try[Something], with the last returning Try[Unit]. Something like this: ...
5
votes
1answer
99 views

Verifying the type of an AggregateException's inner exception in a unit test

I've got the following code inside an integration test. ...
3
votes
1answer
45 views

JSON fetcher for Eclipse plugin — Is this exemplary code for exception handling?

I am planning to use this code as a "good exception handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look? ...
3
votes
1answer
66 views

Exception handling with expression lambda in Presenter class

Following is a code snippet from MVP Win Forms application. My DAL doesn't handle exceptions and it will be propagated up to the calling method in the presenter classes where the exception will be ...
4
votes
1answer
45 views

Follow Up post: Proper handling of exceptions in MVP

This is a follow up post of my early question "Proper handling of exceptions in MVP" So based on the answers I re edited the post and now my exception handling code looks like this... DAL ...
6
votes
2answers
324 views

Proper handling of exceptions in MVP

In my DAL currently I'm handling exceptions as follows. Is it in an acceptable level? Note : I'm using MVP in this Winforms application. ...
6
votes
2answers
182 views

Will this Circuit Breaker catch fire?

I was going to post this code as an answer to a recent question, but I wrote this code a little while ago (like, a year ago; if I recall correctly I wrote this after reading this article) and I'd like ...
7
votes
3answers
268 views

Scrubbing user input

I'm taking user input from a file in form (1, 2, 3) to create a color, and I just wanted to know if I was taking most cases into account, and if there is any way I ...
7
votes
1answer
445 views

Is it bad when my code is throwing exceptions, but doesn't crash during runtime?

Here's part of code in Java for battleships game I'm working on: ...
14
votes
2answers
540 views

Using finally with return statement or not

I was wondering if it is the proper way to always put the return statement of a function with a try-catch clause in the finally ...
7
votes
2answers
357 views

proper way of handling exception while reading user input from file

I am parsing a text file (UTF-8) and checking for several conditions that need to be satisfied for the code to be happy. If not, then there is no point to continue and the program should die. At the ...
0
votes
1answer
55 views

Exception-handling optimisation

I have posed another question here and I am writing this one for some code review: ...
1
vote
1answer
43 views

How to add exceptions in a class that reads a config file?

I am using Boost for reading a config file that is in the .json format. I am using a class to do this and I am calling exit(message) in case of bad values or ...
2
votes
1answer
45 views

Python script to find large folders

I wrote this script a few days ago to find all files which were taking up over a certain threshold of memory on the hard drive. A hard drive on one of my computers had just 6 GB left, so I needed to ...
4
votes
2answers
197 views

Exceptions or something else?

I'm in the process of creating a program that can model points, vectors, lines and segments. I have the classes built and confirmed to be working correctly. The classes are built to handle multiple ...
11
votes
1answer
265 views

Variant class with full move support

I tried to write my own variant class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from ...
6
votes
2answers
86 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: ...
6
votes
1answer
3k views

Reading data from Excel sheet with ExcelDataReader

Objective: I want to import an Excel file, and read the rows of certain columns. For this, I use ExcelDataReader. I've implemented a low-level class called ...
2
votes
2answers
56 views

Java ClassNotFoundException Handling

Is there a better way to handle this ClassNotFoundException ? ...
1
vote
1answer
55 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
54 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. ...
5
votes
3answers
133 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
166 views

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

Would there be any reason to use the following code? ...
7
votes
1answer
463 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
44 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
46 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
466 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
170 views

How to chain exceptions?

I have some function like: ...
4
votes
1answer
80 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
267 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
2k 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
101 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
192 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
44 views

Passing around Connection

I have a myCon=getUnusedConnection() method that gets a connection from Connection pool. I also have a ...
3
votes
1answer
190 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
132 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: ...