An exception is a rarely occurring (exceptional!) condition that requires deviation from the program's normal flow.
19
votes
4answers
3k views
Is it a good practice to put an exception handler in every method?
I always add an exception handler when a new method is created, and I don't know if it is a good or bad practice. I thought it may be a bit of an annoyance when viewing the source code.
Is it a good ...
14
votes
5answers
968 views
What’s your opinion on a Throw() method?
Lately I seem to run into a situation very frequently where I want to write something like the following:
...
14
votes
2answers
911 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 ...
10
votes
12answers
4k views
Can I return a null in a function if something goes wrong?
Lets say I have a function that should return me the information about all textfiles in a folder:
...
9
votes
1answer
581 views
Unhandled Exception handler that captures a screenshot
So, whether you're still in the development stages or your app is already on the app store, you always hope your app isn't crashing. But if it is, you want to be sure you've got good crash reports, ...
8
votes
2answers
440 views
Customized Exception
I am building my "base exception to end all base exceptions" class in C# and was looking for some opinions on my implementations so far. Ideally my usage of integrated Rethrow, Throw, and ThrowFatal ...
6
votes
3answers
668 views
Throwing exceptions when validation fails
When I want to check the validity of an attendance being entered into the system, I perform following action.
AttendancePresenter Class
...
6
votes
5answers
594 views
Handling null exception when having multiple variables
I have a lot of variables that I need to check for exceptions and output the empty field in case of a null returned value (I am reading a calender list from Sharepoint and my program is supposed to ...
6
votes
3answers
6k views
Insert a character into a string
For practicing reasons I would like to write a method which inserts a character into a string.
I would like to know:
What is the best practice concerning placement of a comment within methods? For ...
6
votes
3answers
4k 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 ...
5
votes
2answers
281 views
5
votes
3answers
330 views
5
votes
2answers
418 views
Simple factorial program using recursion
Two concepts I realized I needed to understand and use more are recursion and Exceptions. Thus, I combined both in the following program. Although it began with a focus on using recursion it became ...
5
votes
1answer
223 views
Morse Code Converter
I wanted an uncomplicated project to get myself started again. Although this works I was wondering if it's the best approach, especially when it comes to validation parts? It seems to me that I'm ...
5
votes
1answer
212 views
Rethrowing exception just as an information
I have something like that:
My custom exception class:
...
5
votes
2answers
5k views
Handling COM exceptions / busy codes
This code writes to Excel using the COM interface. The general issue is that any exception handling has to handle the "Excel is busy" exception. This occurs if information is sent to Excel quicker ...
5
votes
2answers
447 views
Throw exception in constructor bad or good practice
I am doing a code review and I have encountered a class in an application that is throwing an exception in the constructor:
...
5
votes
2answers
8k views
Is this the wrong way to handle AggregateException with Tasks
I'm seeing a lot of code like this at my new site
...
4
votes
1answer
145 views
Throw exception in favor of an error?
I've been reviewing my previous projects for the last few days. I've found that I never return an error from any of my methods. I always throw exceptions. I googled about exceptions vs errors and I ...
4
votes
1answer
80 views
Generator expression in combination with StopIteration: kind of a hack?
The first piece of code should cover the standard expected data. But as you can easily see, the data not always conveys to this standard. The code works great but I wonder if this is thought be a ...
4
votes
1answer
969 views
4
votes
0answers
38 views
Extending Exceptions with module-specific prefix, intended for parsing error reporting
For one of my [WIP] project, I extended the dictionary class a lot with specific handlers, as such I determined that I wanted KeyError and ...
4
votes
0answers
2k views
3
votes
3answers
686 views
Reading a text file, need help cleaning exception handling
Which of the following is cleaner / more adopted standard of handling exceptions while coding a stream ? I would also appreciate a reason why one of the following trumps over other ? In my opinion I ...
3
votes
1answer
151 views
3
votes
2answers
105 views
Custom exit with only some exceptions in Python
I want to define an exit code for some exceptions and some exceptions only. I want that the only input is that dictionary with the definition.
...
3
votes
1answer
30 views
Good approach to raise an exception
I have class House and module Lockable. Locking and unlocking House should reflect the real ...
3
votes
2answers
52 views
3
votes
1answer
159 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:
...
3
votes
2answers
115 views
Cleaning up file resources in a DRY manner
I've written a function that generates a report, and then sends it as an attachment to an email. I don't want to clutter the function with a lot of calls to close up the filesystem, if there was an ...
3
votes
2answers
133 views
Guard statement extension methods for common object guards
I wrote a couple of extension methods for common guard statements I write a lot. These are extension methods for Object, and allow me to quickly guard against common scenarios.
I'm using .Net 3.5 ...
3
votes
1answer
617 views
Is there anything wrong with my self-implemented C++ exception class?
I wrote my own exception class, deriving from std::runtime_error to have Error-IDs, timestamps and inner exceptions.
It seems to work, but are there any drawbacks?
...
2
votes
2answers
211 views
“Nice Angles” - Code Eval challenge
Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0:
CHALLENGE DESCRIPTION:
Write a program that outputs the value of angle, reducing its
fractional part to minutes and ...
2
votes
2answers
294 views
Raising an assertation error if string is not an email
I created a class EmailParser and check if a supplied string is an email or not with
the help of the standard librarie's email module. If the supplied string is not an
email I raise an exception.
...
2
votes
2answers
196 views
Closing a ResultSet and rethrowing an Exception
Is this an acceptable way to make sure a java.sql.ResultSet is always closed, and also make sure that an Exception caught is propagated to the caller?
Please don't hesitate to review other aspects ...
2
votes
3answers
863 views
Exception handling continuing the excecution
This code is for continuing the execution after an exception, and this is ugly:
...
2
votes
3answers
636 views
2
votes
2answers
148 views
Python and Exception Handling IOError [closed]
I'm trying to work with exception handling by displaying "No Such File" when the file doesn't exist. I need to use a try statement.
...
2
votes
1answer
3k 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
1answer
244 views
Suggestions for improving error handling
I am interested in finding out what is the correct way of implementing error handling for this situation in C#.
The system tries to do an operation. If the operation succeeded (returns a non-error ...
2
votes
1answer
344 views
Simple factory pattern in scala (attempting to restrict use of new)
I am a Scala newbie and attempting to improve my skills. I have decided to be playful about it and work to do a conversion of the spaceinvaders game supplied with the LWJGL. It consists of 10 Java ...
2
votes
1answer
98 views
Checking if a directory exists in FTP without relying on exception handling?
I've written a method to check if a directory already exists on an FTP server. The only way I could see to make this work was to return a different result from the method if an exception is thrown - ...
2
votes
0answers
257 views
SDL boilerplate
The SDL code example on the SDL_Init page seems to be overly verbose, creating an exception class entirely for SDL_Init. I ...
1
vote
3answers
491 views
Use of Exception to log execution stack trace
I've been back and forth with a colleague over the use of Throwable.fillInStackTrace. This Log class is meant to wrap the Simple ...
1
vote
2answers
59 views
Simple interface and class for holding text to be analyzed
I am making a sentiment analysis library targeted first at social media text (like Twitter) and then I will expand it for more general use.
For the first step I am making a simple interface and a ...
1
vote
3answers
273 views
Java Exception Message
I have a few custom exception classes that I created simply for the sake of having my own exception message:
...
1
vote
1answer
59 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 ...
1
vote
1answer
231 views
1
vote
1answer
201 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
189 views
Stylistic exception and bang usage
I'm not sure whether I should be throwing exceptions in the below model code (and rescuing in the controller - rescues not implemented below) or returning nil (in ...