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
2answers
87 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
38 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
338 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 = ""; } ...
0
votes
0answers
22 views

How can I verify if an input is either a json string or a file containing json in python? [closed]

I've got a small module that reads JSON strings and does something with the data they contain. It's designed to accept both JSON strings and files that contain JSON. Consider this code: import os ...
0
votes
1answer
45 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
27 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
74 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
48 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
96 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
107 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
1answer
38 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
103 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
40 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
161 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
135 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
280 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 ...
5
votes
1answer
138 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
130 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
74 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
155 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
2k 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
97 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 ...
7
votes
3answers
290 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
452 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
182 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
264 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
197 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
325 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
149 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
334 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
112 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
489 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
116 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
159 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
561 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
206 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
106 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
163 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
105 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
59 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
160 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
154 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
681 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
140 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
181 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
2k 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
834 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
119 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
173 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
2k 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 ...

1 2