An exception is a rarely occurring (exceptional!) condition that requires deviation from the program's normal flow.

learn more… | top users | synonyms

5
votes
2answers
196 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 ...
5
votes
3answers
112 views

How to chain exceptions?

I have some function like: void foo() { ... } int main() { ... try { ... foo(); ... } catch (const std::exception &e) { std::cout << "Fatal error: e.what() << ...
17
votes
4answers
2k 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 ...
4
votes
1answer
64 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 ...
3
votes
1answer
71 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) { ...
1
vote
0answers
78 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 wanted to tone it down a bit by making everything std::runtime_errors. Does ...
3
votes
1answer
120 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 ...
3
votes
3answers
175 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
135 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; } ...
0
votes
1answer
79 views

Function that uses an exception to check if user exists

I have a User class that will throw an exception if the userid provided in the parameter does not correspond with a user. I've written a helper function that will return true or false depending on ...
0
votes
2answers
106 views

Try, catch, exceptions with java

Is this code good for checking if the variable texto is empty or not? How would it be done with try and catch? public class RedProfesionalException extends Exception { public ...
0
votes
1answer
65 views

How to handle returned value if an exception happens in a library code

There is a lib code, trying to parse an Element Tree object. If exception happens, it either returns an empty dict of dict or a partially constructed object of such type. In this case, caller needs to ...
1
vote
1answer
865 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
206 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. ...
1
vote
3answers
116 views

Java Exception Message

I have a few custom exception classes that I created simply for the sake of having my own exception message: public class DivideByZeroException extends Exception { @Override public String ...
2
votes
2answers
128 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 ...
6
votes
5answers
264 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 ...
3
votes
1answer
316 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? The only thing I see is the ...
10
votes
12answers
2k 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: public static FileInfo[] GetTxtFiles() { //... FileInfo[] files = directory.GetFiles("*.txt"); ...
2
votes
1answer
211 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 ...
16
votes
6answers
4k views

Is it better practice to have void method throw an exception or to have the method return a boolean?

This falls straight into the same category with the recent "Is it better practice to return if false or execute an if statement if true?" question. Often, while writing code, I find myself presented ...
2
votes
2answers
931 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 ...
1
vote
1answer
157 views

Rails stylistic exception and bang usage

Question whether I should be throwing exceptions in the below model code (and rescuing in the controller - rescues not implemented below) or returning nil (in both or one of the exception cases). ...
0
votes
1answer
62 views

uplifitng return value error reporting to Exception based error reporting

In Framework Design guideline book there is a chapter about Exception and they talk about return-value-based error reporting and exception based error reporting and the fact that we in a O.O language ...
1
vote
1answer
137 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 ...
4
votes
2answers
5k views

Is this the wrong way to handle AggregateException with Tasks

I'm seeing a lot of code like this at my new site try { Task.Factory.StartNew(() => { ... }); } catch ...
2
votes
3answers
234 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: ...
2
votes
1answer
330 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
214 views

Critical review of a Simple Class

public partial class CreateAdmin : System.Web.UI.Page { #region Events. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ...
4
votes
0answers
1k views

try-catch inside or outside a loop when rethrowing it [closed]

try { for (int i = 0; i < n; ++i) { nothrow_stuff(); could_raise_an_exception(); nothrow_stuff(); } } catch (...) { ensure_everything_is_fine(); throw; } ...
3
votes
1answer
887 views

An implementation of “finally” in C++0x

I've made a quick finally type in C++: template<class F> class finally_type { public: explicit finally_type(F f) : function(f) {} ~finally_type() { try { function(); } catch (...) {} } ...
2
votes
2answers
3k 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
3answers
526 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 ...
13
votes
5answers
919 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: var x = condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : ...
9
votes
4answers
1k 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 ...
5
votes
2answers
3k 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 ...