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

learn more… | top users | synonyms

1
vote
1answer
67 views

Why is Throwable initCause designed to be called only once?

I find it really odd that the initCause method of Java's Throwable class can only be called once, or even not at all (if the constructor accepting a Throwable was used). This makes exception chaining ...
2
votes
1answer
49 views

Is it good practice to use NoStackTrace in scala?

I came across the NoStackTrace mixin for Exceptions in scala. Is it good practice to use it, or should it be considered "internal" to scala and left alone?
0
votes
5answers
257 views

Should we only catch in exceptional circumstances?

Whether error handling by throwing exceptions is good or bad is contentious. Are exceptions as control flow considered a serious antipattern? If so, Why? The common line is that exceptions are for ...
0
votes
4answers
57 views

alerting that an object cannot be deleted (due to constraints)

Assume an application with a rich domain model with many classes (e.g School, Classroom, Teacher, Student, Course, Exam, Submission, ...) linking to each other. Model and links are mapped to the ...
3
votes
1answer
52 views

When to declare @throws with a Scala annotation - abstract parent or concrete implementation?

In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my ...
3
votes
1answer
167 views

Java-Like 'throws'-information in method signature C#

From Java I know that the signatures of methods that can throw exceptions contain a throws block, that contains the Exception(s) that might be thrown. In C# there is no such thing and it is also not ...
3
votes
4answers
200 views

How much data should exceptions hold?

Almost all the exceptions I have ever written have been very lightweight, containing a String message and optionally a throwable. In some situations I have included some application specific enum or ...
4
votes
2answers
79 views

How do you handle specific networking exceptions in Haskell?

I have the following to try and connect to a server: testAddress :: HostName -> Int -> IO (Maybe Handle) testAddress host iPort = do let port = PortNumber $ fromIntegral iPort putStrLn ...
5
votes
1answer
104 views

Why are F# exceptions generally not suffixed with 'Exception'?

In .NET, it is idiomatic to suffix exception types with Exception. But most, if not all, sources I have seen for custom exception types in F# don't follow this idiom. Most seem to use the suffix ...
1
vote
1answer
98 views

Pros and cons of custom exceptions [duplicate]

This may be an pointless question based on opinion, style, and context but I've been racking my brain trying to decide whether or not to make use of custom exceptions and would love to hear some pros ...
0
votes
2answers
160 views

IllegalStateException vs. IllegalArgumentException

In have written a function which expects the caller to pass in a configuration file like XML. Then I parse this given file and extract something which i then return. In this function (at least) two ...
35
votes
11answers
4k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
0
votes
2answers
136 views

Expected error handling

Let's say I have a social media website. On this website, users can upload several pieces of information about themselves, including their phone number. To implement this, I have a class called ...
0
votes
0answers
82 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
90 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 ...
2
votes
2answers
94 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 ...
10
votes
6answers
1k 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 ...
0
votes
1answer
161 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
147 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 ...
2
votes
1answer
194 views

Should we encapsulate everything in a try{} block in a Try object?

Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical? class DBConnectTry extends Try { TryResponse response[] attempt(TryObject ...
0
votes
3answers
82 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 ...
1
vote
3answers
230 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 ...
3
votes
5answers
635 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 ...
3
votes
1answer
159 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 ...
0
votes
1answer
156 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 ...
14
votes
1answer
871 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 ...
3
votes
4answers
301 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. ...
1
vote
1answer
210 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
168 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. ...
7
votes
2answers
2k 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
54 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 ...
2
votes
1answer
89 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
424 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 ...
3
votes
1answer
133 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
200 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 ...
16
votes
1answer
1k views

Workaround for Java checked exceptions

I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
0
votes
5answers
187 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
123 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
241 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 ...
-1
votes
1answer
132 views

Making my code more robust [closed]

I have recently finished a piece of code that passed all tests. (Here is some idea what it does and Here is some actual code.) Problems began, however, when I run my code on the cloud with actual ...
2
votes
1answer
116 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. ...
1
vote
1answer
208 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 ...
8
votes
3answers
551 views

When and how should I use exceptions (in Python)?

The Setting I often have trouble determining when and how to use exceptions. Let's consider a simple example: suppose I am scraping a webpage, say "http://www.abevigoda.com/", to determine if Abe ...
0
votes
2answers
327 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 ...
3
votes
2answers
198 views

Understanding exceptional cases

I've been studying the use of exceptions in various php projects (such as Doctrine and Zend Framework). Exceptions seem to be thrown when unordinary input/state occurs. A perfect example is Doctrine ...
5
votes
4answers
672 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 ...
2
votes
3answers
470 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 ...
1
vote
4answers
441 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(); } ...
3
votes
3answers
202 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 ...