An exception is an occurrence in an application process that requires deviation from the program's normal flow.

learn more… | top users | synonyms

0
votes
0answers
84 views

How to void checked exceptions in Java? [duplicate]

I consider checked exception for a design mistake in the Java language. They lead to leaky abstractions and a lot of clutter in the code. It seems that they force the programmer to handle exceptions ...
0
votes
2answers
106 views

What should happen when code is reached that shouldn't be, according to business or logic rules? [duplicate]

I am currently writing an application that isn't huge but will be used through-out my company of 200+ people and external customers about projects we are working on (not software projects), but there ...
3
votes
2answers
175 views

Retried Operation with generic Exception

I am looking for a way to get the logic of retrying an operation in a single method while keeping the exception types of the operation. I.e., the implementation to retry an operation could look like ...
3
votes
1answer
174 views

Should I assert in packages? [duplicate]

I have read a few asserts vs exception questions already; I ask specifically about package visible classes though. When you write a package, the classes marked with "public" are exposed to the ...
10
votes
6answers
2k views

Should you throw an exception if a method's input values are out of range? [duplicate]

Should you throw an exception if a method's input values are out of range? eg //no imaginary numbers public int MySquareRoot(int x) { if (x<0) { throw new ...
-1
votes
1answer
176 views

How to determine what throws an exception [closed]

Whenever I encounter crashes, the exact type of the exception usually already gives enough info to easily find the culprit. FileNotFoundException will hardly occur while using sockets. Now recently ...
0
votes
1answer
178 views

Is ok to throw exception in normal code path which eliminate a possible programmer error? [duplicate]

I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception. But what happen ...
1
vote
3answers
252 views

Exception when logging exception: is it correct to ignore them?

My question is specific to php, but i think it can be useful in other languages. I log into a table all the exception a code can throw: try{ //Some code } catch (Exception $e) { $log = new ...
0
votes
3answers
86 views

Should I use an Exception in a case like this? [duplicate]

I have a Windows service with a fluent interface like this: aRequest = Repository.getRequest() .createProcess() .validate(); Sometimes getRequest() could ...
8
votes
5answers
962 views

“Programming error” exceptions - Is my approach sound?

I am currently trying to improve my use of exceptions, and found the important distinction between exceptions that signify programming errors (e.g. someone passed null as argument, or called a method ...
3
votes
5answers
877 views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
12
votes
8answers
2k views

In Java, what are checked exceptions good for? [closed]

Java's checked exceptions have gotten some bad press over the years. A telling sign is that it's literally the only language in the world that has them (not even other JVM languages like Groovy and ...
-1
votes
1answer
168 views

Functions returning either “OK” or “error message” instead of procedures

I have joined writing middle-size multi-purpose database application as co-lead. It currently has about 150 tables (and growing) and overall functionality you can imagine as very small ERP. At many ...
3
votes
4answers
327 views

Should exceptions do things other than tell the user something went wrong?

I created a general class that accepts a string when it is constructed, and it spits out that string when a user calls what(). This is all it does; on throw, it returns the initializing string. ...
14
votes
1answer
875 views

Is it fine to make a default constructor unusable?

Specifically asking about the default constructor Given that the constructor initializes all the data for an object, if I create a class that can't be used without proper initialization, is it not ...
1
vote
1answer
280 views

Separate namespace just for exceptions?

I was doing a code review and came across something odd which I've never seen before. The developer decided to create a sub-namespace just to contain all the assembly's exceptions. I thought I had ...
3
votes
2answers
179 views

Is it an acceptable practice to Get a property, that involve parsing binary, that might throw an exception?

I have a property that is loaded lazily, any time after the ctor is called. It is possible that the binary that my property relies on is invalid. If invalid I might have to throw an exception. ...
10
votes
2answers
3k views

Is it conventional to raise a NotImplementedError for methods whose implementation is pending, but not planned to be abstract?

I like to raise a NotImplementedError for any method that I want to implement, but where I haven't gotten around to doing it yet. I might already have a partial implementation, but prepend it with ...
1
vote
1answer
55 views

Partial recovery from an Exception [duplicate]

I have seen Exception Handling blocks that they were throwing the recently caught Exception in the catch block. Something like: } catch ( Exception $e ) { // Do some recovery here ...
3
votes
1answer
108 views

Exceptions catching clutter code and make it hard to read

When I read well written code that checks to make sure all the input is of the correct format and type, and also catches all the things that possibly could go wrong, I find it difficult to understand ...
19
votes
2answers
1k views

What is the advantage of wrapping exceptions [duplicate]

It's very common in .NET for an exception to be wrapped in several layers of "outer exceptions" which give marginally more contextual data. For example, in EF if your update fails, you get exceptions ...
2
votes
2answers
639 views

Doing work in vector's push back

I often use the following syntax: std::vector<foo> vec; vec.push_back( someClass.getFoo(...).modifyAndReturn() ); Considered about exception safety, I quote the standard on vector's push back ...
9
votes
6answers
2k views

Maybe monad vs exceptions

I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax. update Please note that I'm intentionally ...
3
votes
1answer
140 views

Etymology of “throw an exception“ [closed]

Why do we use the expression “throw an exception“ and not something like “generate“? Where was that term born and in which language?
1
vote
3answers
257 views

C API in C++ with RAII, two alternatives to implement error handling (Exceptions)

I have an API written in C, which produces a result by returning a pointer to allocated memory. For using it with C++ (C++11) I've wrapped the function calls in objects, which keep the result in a ...
4
votes
2answers
307 views

Nulls in every type and checked exceptions in Java?

I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that ...
0
votes
5answers
249 views

Fail-fast paradigm overheads

Fail-fast seems like a right way since it simplifies bug detection. But it's a harm for performance cause of multiple checking the same thing at several levels of the system. Simple example. There is ...
3
votes
2answers
125 views

Inform caller or just let them deal with exception?

I'm not sure how to proceed in the following situation. say we have a function as so: def runsATask(codes): myDicts = [helperFunc(code) for code in codes] for item in myDicts: # some ...
3
votes
3answers
282 views

Does Exception Handling Violates “Program to Abstraction”? [duplicate]

I am talking based on experience with Java and C#. I do not know if other language have different exception handling implementation. In order to achieve loose coupling, we need our code being ...
40
votes
10answers
3k views

Why are exceptions considered better than explicit error testing? [duplicate]

Possible Duplicate: Defensive Programming vs Exception Handling? if/else statements or exceptions I often come across heated blog posts where the author uses the argument: "exceptions vs ...
8
votes
3answers
1k views

Exceptions or Error codes

We are building a web service(SOAP, .Net) which would be talking to (mostly) native clients (windows, C++) and we are wondering what is the best way to communicate errors to the client (e.g. ...
2
votes
1answer
130 views

How to handle when one user deletes the object while the other has it opened in edit mode in a webapp?

I am developing a CRUD type web application. It is a project management system having projects, milestones, tasks, employees etc. Each employee has his/her own account to login and view the system. ...
0
votes
1answer
226 views

Either Monad and Exceptional Circumstances [duplicate]

I have a function returning an Either such as GetUserFromDb(int id). If the database is offline, should I catch the error in the function and wrap it in a failure / Left case or should I let it ...
0
votes
2answers
417 views

Is storing stack traces in database recommended?

The current system I am working on goes through a set of documents & performs some logic using the metadata of the document. If the metadata of a document is fishy..it throws an exception. The ...
54
votes
11answers
5k views

I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. ...
5
votes
4answers
724 views

What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]

AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
21
votes
2answers
1k views

Who designed exceptions?

Where did exceptions and exception handling come from? I like how .NET uses it, I like how C++ supports it (but libraries unfortunately use return code or is written in C instead). I know its pretty ...
2
votes
3answers
494 views

Layering Design Pattern in Java clean code style

As a Java developer, I am developing trying to use the clean code rules. But in my team we are facing a concrete problem: We have a business layer offering a service called "createObject", this ...
3
votes
3answers
228 views

Throwing exception from a property when my object state is invalid [duplicate]

I am aware that for the general case, the answer to "should I throw an exception from a property" is "generally don't, but in some special circumstances it is OK to do so". There is a Microsoft ...
37
votes
20answers
6k views

Is it ever ok to have an empty catch statement?

I thought about it and could not come up with an example. Why would somebody want to catch an exception and do nothing about it? Can you give an example? Maybe it is just something that should never ...
38
votes
7answers
3k views

Are there legitimate reasons for returning exception objects instead of throwing them?

This question is intended to apply to any OO programming language that supports exception handling; I am using C# for illustrative purposes only. Exceptions are usually intended to be raised when an ...
13
votes
2answers
1k views

What is a 'good number' of exceptions to implement for my library?

I've always wondered how many different exception classes I should implement and throw for various pieces of my software. My particular development is usually C++/C#/Java related, but I believe this ...
1
vote
4answers
571 views

What's the difference between the code inside a finally clause and the code located after catch clause?

My java code is just like below: public void check()throws MissingParamException{ ...... } public static void main(){ PrintWriter out = response.getWriter(); try { check(); } ...
6
votes
13answers
2k views

Should integer divide by zero halt execution? [closed]

I know that modern languages handle integer divide by zero as an error just like the hardware does, but what if we could design a whole new language? Ignoring existing hardware, what should a ...
2
votes
3answers
376 views

What code lays behind C++ exception?

In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data ...
2
votes
1answer
340 views

Why would one transform a checked exception to an unchecked exception? [duplicate]

My buddy told me today that some programmers transform a checked exception (e.g. EJBException, SQLException...) to an unchecked (RuntimeException?) My buddy explained a call stack where if you change ...
1
vote
2answers
279 views

Java exception redundancy

To what extent should one make exceptions redundant or atomic to a method. For instance, suppose I have a method public void authenticate(String username, String password) that calls private void ...
21
votes
4answers
8k views

Why do iterators in Python raise an exception?

Here's the syntax for iterators in Java (somewhat similar syntax in C#): Iterator it = sequence.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Which makes sense. Here's ...
12
votes
6answers
2k views

What's the best way to manage error logging for exceptions?

Introduction If an error occurs on a website or system, it is of course useful to log it, and show the user a polite message with a reference code for the error. And if you have lots of systems, you ...
1
vote
3answers
219 views

Throwing an exception for errors that can be fixed

Say I have a class like this: public class MyObject { public List<string> MyCollection { get; set; } } And a method like this: public void DoSomething(MyObject object) { ...