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.
1
vote
2answers
30 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
117 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
115 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
263 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 ...
4
votes
1answer
100 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
100 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
62 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 ...
5
votes
2answers
149 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 ...
4
votes
2answers
489 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, ...
4
votes
1answer
74 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 ...
6
votes
3answers
231 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
344 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 ...
5
votes
2answers
136 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
210 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 ...
4
votes
3answers
169 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 ...
6
votes
4answers
314 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
136 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) ...
6
votes
3answers
312 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 ...
1
vote
2answers
98 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 ...
3
votes
2answers
391 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 ...
2
votes
3answers
113 views
I think I'm not using Try Except properly in this Python code
Please offer some advice for this code. It all works, but I know that its messy and I don't think the Exception catching is doing what I want it to. Thanks in advance for any and all advice...
def ...
1
vote
1answer
116 views
LPTHW - ex48 - Handling exceptions and unit testing
This is my solution to the exercise 48 of Learn Python the hard way by Zed Shaw. Please visit the link for testing suite and requirements.
I'm worried about my the word banks I have created (COMPASS, ...
2
votes
2answers
473 views
HttpClient error handling
I would be happy to hear feedback on my implementation of httpclient. I am not so strong with error handling so I want to improve. My thought process behind this was that IOExceptions can be ...
2
votes
2answers
174 views
Is this right way to implement Abort, Retry and Ignore activity pattern?
I've a bunch of sequential activities. These are long running. Once an activity is complete, it can't be rolled back. Now something deep down the line fails. Now I've few options
Report this to end ...
1
vote
1answer
101 views
PHP - Is this proper use of exceptions for error handling within classes?
I've searched plenty on this topic and have gotten a lot of good (but different) results. Some of the results weren't quite related and it does seem to be a matter of preference in the end, but I'm ...
1
vote
1answer
144 views
Could this php error/exception handling be better?
I'm VERY new to error/exception handling, previously just echoing everything to screen, and am trying to really clean up my code. My goal was to log everything but only show the user a friendly ...
1
vote
2answers
94 views
extending Exception to allow for auto appending class name on exception message
Got this idea from the php.net website on extending exceptions. The main thing I wanted with this was to have the exception name auto imprinted on the exception message, so I wouldn't have to write it ...
2
votes
1answer
58 views
How can I improve CreateGenre() function?
I use this function in my wordpress site to add genres to an album:
What is it that makes this code so bulky?
Is it have for the server or it just looks like?
/**
* Creates a genere. If one already ...
2
votes
3answers
154 views
Exception handling continuing the excecution
This code is for continuing the execution after an exception, and this is ugly:
int step=0;
do{
try{
switch(step)
{
case 0:
...
4
votes
2answers
148 views
Asserting when cleanup is required
I've been looking at ways to use asserts in programs that must do some kind of cleanup on fatal errors, and have arrived at the following pattern (PROJECT being replaced by the name of the project):
...
6
votes
6answers
660 views
How to reduce the amount of try/catch in my code?
I have the following code that checks for three different properties. Unfortunately each call can throw up to four exceptions that I all have to catch. Can I some how make the code more readable by ...
1
vote
1answer
122 views
Learning Simple Operating System Tools: Experienced Tips?
Operating system code, I've noticed, has two outstanding properties:
1. It's everywhere, and vitally important to functional software
2. It has *lots* of exceptions.
Please give me some pointers on ...
2
votes
2answers
168 views
Is it acceptable to pass an Exception into a function that then may or may not throw it?
I am still getting the hang of Exception Handling in PHP; Here is the scenario where I am using the convention:
There are times where I have a SQL query that I need to turn into an object, so I wrote ...
5
votes
6answers
1k views
Could this ExecuteScalar call be written better?
I came across this code in our project today. Where possible I'm trying to leave the code base in a better shape than I found it, as I go along, and this method jumped out at me for a number of ...
2
votes
1answer
674 views
Validating files and returning errors messages/boolean values
I am writing simple file validator for my java ee app and I am stack with my class api. I need specific error descriptions, but also I would like to have boolean values indicating whether file is ...
3
votes
2answers
114 views
Is my error handling feasible when dealing items not found in an array?
internal void ShiftSwapInstrument(SwapCurve shiftedCurve, string swapToShift)
{
if (SwapExists(shiftedCurve, swapToShift))
{
var rateToShift = shiftedCurve.Swaps.Single(r => ...
2
votes
1answer
170 views
Is This a Sufficient Demonstration of the Effects of Exception Handling
We have some developers in house that believe it is best practice to use exception handing as flow control, as well as, thinking that catching and re-throwing exceptions is effective error handling.
...
2
votes
2answers
1k views
Generic C++ exception catch handler macro
I have this set of legacy C++ projects with a large number of public functions. At the start none of those publicly exposed functions had try..catch insulation inside them. When a C++ exception ...
2
votes
2answers
300 views
Open database and hande errors
How to make this code better?
if (Program.Data.DataBase.TryOpenDataBase())
{
bool result;
DataBase= new Program.Data.DataBase(out result);
if (!result)
{
if (Program.DataBase!= null)
...
2
votes
3answers
431 views
Clumsy try catch - how to perfect it?
I have the following construction in the program:
while(true) {
<...>
try {
JobManager.markJobCompleted(unitOfWork.getSqlFactory(), jobId, dataOut);
} catch ...
7
votes
4answers
752 views
Providing unchecked exception “wrapper” interfaces for an API with checked exceptions
I recently had a discussion in the forum of an API, because they changed an exception from checked to unchecked. I believed it needs to be checked, because it is recoverable. The arguments of "the ...