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

learn more… | top users | synonyms (1)

0
votes
3answers
155 views

A very basic question about whether I should check for null and throw NPE? [duplicate]

Consider the below method- public void operationOnList(List<String> list) { list.add(1); } It is obvious that if l is null this method will throw a NullPointerException. My question is ...
1
vote
1answer
75 views

When we need to serialize an exception

I have been developing in Java since 8 months, and I didn't face a case where I went to serialize an exception, I'm asking because I saw the serialVersionUID and how Eclipse advise to add it ...
1
vote
2answers
63 views

Catching Exception and Recalling same function?

I have a function which sends data to a third-party's server using a library they've supplied. The function is very simple. It just takes a list of objects to send, loops through each item in the ...
11
votes
5answers
332 views

Is indiscriminately catching exceptions (Pokemon exception handling) ever acceptable? [duplicate]

Normally, I don't anticipate exceptions and if I get them, its something that I can't fix in my code - bad user input or connectivity issues with the database. But errors do occur so at the very ...
3
votes
5answers
105 views

Use Exceptions for control flow in order to increase performance?

I add a lot of elements to a list of lists. If the list of lists my element should be saved to, does not exist yet, I handle this by catching an exception and adding a new list to my list of lists. ...
4
votes
2answers
86 views

Under what scenarios would 'functional' `Try` objects be more or less beneficial than 'rx' `Try` objects?

Definitions used by this question: 'functional' Try is what https://github.com/lambdista/try is. Success and Failure are subclasses of Try. Exceptions aren't thrown by the called function. 'rx' Try ...
14
votes
11answers
2k views

What is better IllegalStateException or silent method execution? [closed]

Let's say I have a MediaPlayer class which has play() and stop() methods. What is the best strategy to use when implementing the stop method in case when the play method has not been called before. I ...
-2
votes
1answer
81 views

Why can't be “real” custom exceptions be created? [closed]

By "real" I mean Exceptions that would work as the ones predefined by the system. I mean for a custom exception you have to use the reserved word throw CustomException once you have checked the ...
1
vote
1answer
86 views

Standalone library for error logging?

Background Here is how I currently log any exceptions that occur in my code: Pass each object instance the path to a file where I want all of the logging to happen. Each of the objects have their ...
2
votes
1answer
29 views

Appropriate Exception Type for Connecting to a Device via COM port

I'm working on creating a C# wrapper library around a native C library that allows me to directly communicate with a particular piece of hardware over a serial (COM) port. Of course, the C library ...
1
vote
1answer
107 views

The Same Behavior for Boolean and Exception

The following code uses a boolean preference active: In the active state, it does an operation which could throw an exception. On this exception, it does fall back to the non-active state. let active ...
-1
votes
2answers
93 views

How to validate Exception messages? [closed]

My superior asked me to validate each and every input field in the project that includes the Exception messages. So, am I correct in using Exceptional Handler for validating Exception message. ...
0
votes
1answer
71 views

Why is a Spring's HttpClientErrorException an unchecked exception?

Oracle summarises the purpose of unchecked exceptions as: The next question might be: "If it's so good to document a method's API, including the exceptions it can throw, why not specify runtime ...
3
votes
4answers
158 views

How to name an exception where condition is not exceptional

NOTE: This question is about finding a proper name for an exception where the condition for throwing the exception has not actually happened (eg. preventing a StackOverflow by throwing a ...
2
votes
2answers
85 views

Java EE exceptions for validation and APMs

In my current work, we have some Java EE applications and we use exceptions and exception mappers to deal with user errors, i.e. that can't be dealt with in the frontend. We usually reply with a 400, ...
2
votes
3answers
109 views

Dealing with runtime exceptions when reading from file

Let's say I read a bunch of numbers from a text file. Each line is initially a string, I need to parse it to an integer. This is where the first exception might happen - NumberFormatException thrown ...
-1
votes
2answers
161 views

Exception Handling: When and Why?

The main languages I use are C++ and Java. Both languages support exception handling. I confess, I may not actually understand exception handling, at least, I certainly don't understand why you ...
4
votes
1answer
110 views

Overflow Exception Checking Problem

Background I have to call a method that needs to return a signed integer (see code block below) after converting from an unsigned integer. The reason for this is that I have to do bit-wise math that ...
6
votes
2answers
119 views

Returning Unmodifiable Collections only tees you up for runtime exceptions?

Seeing as how there are no distinct Unmodifiable Collections interfaces, aren't you just setting yourself up for runtime exceptions by returning Unmodifiable Collections from method invocations? ...
4
votes
1answer
117 views

Throwing an exception from within a constructor of an exception

As I was TDD-ing some code, it occurred to me that one of my typed exceptions could potentially throw a NullReferenceException while creating its error message. Here's the constructor for the typed ...
3
votes
2answers
110 views

Is an attempt to create a duplicate resource, e.g. a user, worthy of throwing an Exception?

Say I have an REST API for creating users in an application. The request goes to a controller, which marshals the request data into a domain object, and passes it to a service to create a user. Now, ...
2
votes
0answers
75 views

Design interfaces with annotated exceptions, but reduce the need for exception wrapping / re-branding?

I am designing a library with a bunch of interfaces with annotated exceptions. (The example is in (pseudo)PHP, but I am sure one could do something equivalent in Java or other.) For now, the ...
2
votes
2answers
267 views

Error handling in C++

So, in the recent weeks I delved into C++ programming, and I programmed some things in SDL. Doing so, you always have to deal with a lot of (ugly) C++ code, which looks more like C than C++. One thing ...
3
votes
4answers
249 views

Exception treatment with/without recursion

I've entered in an argument with a fellow colleague about a piece of code. While he thinks that it is ok, I don't. But I don't have any more arguments than that calling the same method (recursion) in ...
41
votes
8answers
4k views

Should I throw an exception in case of a meaningful value outside of the range or handle it myself?

I have written a struct that represents latitude/longitude coordinates. Their values range from -180 to 180 for longtitudes and 90 to -90 for lattitudes. If a user of that struct gives me a value ...
0
votes
1answer
108 views

What is considered best practice for custom exception classes?

Python has many strong conventions but I'm unclear on how best to manage exceptions for my module. I know it's generally good practice to define a custom exception for your module. E.g.: class ...
1
vote
1answer
51 views

How to find the cause of an exception in async code

I often see myself trying to follow my own code to find out where the exception came from. The typical example is when some parsing fails, and I catch the execption. Then I spend a ridiculous amount ...
0
votes
0answers
54 views

Is Shiro's use of Auth Exceptions an example of control flow? [duplicate]

In Java/OOP-land, it is a well established anti-pattern to use exceptions for control flow. Apache Shiro is one of the standard Java security frameworks. When using Shiro, especially when ...
12
votes
2answers
2k views

Is using Exceptions at the highest level of a program considered bad practice? [duplicate]

I have seen programs using this strategy and I have also seen posts considering this bad practice. However, the posts considering this bad practice have been written in c# or some other programming ...
25
votes
7answers
2k views

Should a C++ program catch all exceptions and prevent exceptions from bubbling up past main()?

I was once advised that a C++ program should ultimately catch all exceptions. The reasoning given at the time was essentially that programs which allow exceptions to bubble up outside of main() enter ...
1
vote
1answer
81 views

Does exception handling belong at the lowest level of the runtime?

I'm designing a fairly simplistic stack-based programming language, and implementing it in Python. (no link, because it's not fully implemented yet.) The language itself is essentially intended to be ...
5
votes
4answers
255 views

Handling exceptions I don't know about

When I work with handling exceptions, I notice that I often have to deal with the ones I had no idea about. Especially it is noticeable when I program a method that grabs data from web. An error may ...
3
votes
1answer
161 views

what happens at Java interpreter level when IncompatibleClassChangeError is thrown?

I am a noob at JVM internals. Can someone explain what happens at Java interpreter level when IncompatibleClassChangeError is thrown? I am facing an issue similar to the one described here: ...
0
votes
1answer
104 views

How can you catch all index out of range errors in python?

Our program does these kinds of operations hundreds of times for many different variables and lists, then uses them throughout the program: variable = values[5] The list values are coming from the ...
1
vote
2answers
76 views

Should a client check for persisted item existence before modifying it?

I'm developing a MVC Web application with a REST interface. The REST controller performs actions on persisted items through a service class, which translates exceptions coming from the persistence ...
3
votes
3answers
166 views

Are exceptions only for handling errors?

I have a script that throws exceptions when something goes wrong. However, for the purposes of testing I also want to capture specific points although I'm not sure whether they would be deemed errors ...
1
vote
2answers
35 views

Exception Handling for class attributes in setters and constructors [closed]

I would like to discuss a question about best practices regarding exception handling (e.g. in Java). Normally, when setting the attributes of a class, I check the arguments in the setters for ...
-4
votes
5answers
304 views

Differences between `throw` and `throw new` and exactly how exceptions “bubble up” [closed]

Can someone please explain the differences in C# between: throw throw new and exactly how exceptions "bubble up" as I've heard they do? In my daily job, I've used just try/catch to mostly ...
-2
votes
1answer
45 views

Convention for exception argument order [closed]

Just a quick question about a design pattern for creating custom exceptions. The question is more about the order of parameters. If you can specify more data in the exception, should the parameter for ...
12
votes
6answers
437 views

Should I log errors on exception throwing constructors?

I was building an application for a few months and I come to realize a pattern that emerged: logger.error(ERROR_MSG); throw new Exception(ERROR_MSG); Or, when catching: try { // ...block that ...
5
votes
2answers
195 views

How to get around non-initialized objects in the `finally` block?

I like using final variables whenever possible. Often those variables have to be closed afterwards. Note that I'm currently working on Java 6 so there is not closeable interface, but the same applies ...
20
votes
3answers
2k views

Exceptions - “what happened” vs “what to do”

We use exceptions to let the consumer of the code handle unexpected behaviour in a useful way. Usually exceptions are built around "what happened" scenario - like FileNotFound (we were unable to find ...
7
votes
2answers
1k views

Should one derive / inherit from std::exception?

While designing my first 'serious' C++ library, I'm asking myself: Is it good style to derive ones exceptions from std::exception and it's offsprings?! Even after reading Designing exception ...
4
votes
3answers
120 views

Drawbacks of a master error handler?

I'm thinking that I could simplify my life by making an exception handling class that I can just ship all exceptions to and it will handle appropriately. Ideally: def dostuff(): try: dothis() ...
0
votes
1answer
49 views

Include exceptions in activity diagrams? [closed]

Should I include exceptions, like a TimeOutException or just general Exceptions, to a activity diagram? For example: A activity diagram describing a client-server connection. Several exceptions can ...
10
votes
5answers
595 views

What is the conceptual difference between finally and a destructor?

First, I am well aware of Why is there no 'finally' construct in C++? but a lengthy-growing comment discussion on another question seems to warrant a separate question. Apart from the issue ...
-3
votes
2answers
198 views

Why ever use exception throw (in C#) except for Class Library development? [duplicate]

Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change). To be more specific, ...
2
votes
3answers
93 views

Is there particular circumstance that throwing root superclass exceptions is a good practice?

I've been taught that exceptions should be have concise meanings and should contain a message that explains to the client what the exceptional situation is. I am wondering, since I found a piece of ...
8
votes
2answers
419 views

Is the strong exception safety guarantee with a pass-by-value argument which can throw on destruction possible?

Suppose you have a type with a throwing destructor, and a function receiving it by value. Can that operation ever provide anything better than the basic exception guarantee? Or formulated differently, ...
0
votes
1answer
153 views

Low cost exceptions implementation using metaprogramming [closed]

(preface - boring stuff, feel free to skip down to the implementation details) I need to provide exception handling to a language I am working on. It "compiles" to a subset of C, and since I don't ...