Skip to main content

All Questions

Filter by
Sorted by
Tagged with
2 votes
1 answer
188 views

Consider the following code snippet: class Foo { Baz baz; // ... void bar() { int p = this.baz.doSomething(); if (p == this.x) { throw new FooException('Invalid values', ...
user avatar
2 votes
4 answers
2k views

I have a global position keeper of screen items so items don't need store their own positions. class Screen_Position_Keeper: # functions to add stuff def get_px_row( self, item ): ...
user2738698's user avatar
4 votes
0 answers
463 views

Is there a universally accepted classification of error handling strategies? What is a general term to refer to those strategies, which can be used while searching for books and articles that compare ...
michau's user avatar
  • 149
35 votes
5 answers
52k views

I'm building an API, a function that uploads a file. This function will return nothing/void if the file was uploaded correctly and throws an exception when there was some problem. Why an exception ...
Accollativo's user avatar
26 votes
6 answers
7k views

Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this ...
Eyal Roth's user avatar
  • 623
9 votes
4 answers
6k views

Let's say that we have a class PersonName and we throw an exception when some one try to create a instance of PersonName passing an invalid name to the constructor. Should the exception ...
Lucas Piske's user avatar
8 votes
5 answers
9k views

Can anyone explain what exactly Microsoft means on the below linked page when it says: "Do not catch an exception unless you can handle it and leave the application in a known state." https://msdn....
user1451111's user avatar
4 votes
1 answer
137 views

Suppose I am writing a program in F# for end-users. If there is an unhandled exception, the program will crash. Now suppose that I want application-specific data in the crash report. I can get this ...
Demi's user avatar
  • 826
3 votes
1 answer
501 views

I am trying test driven development for the first time (test first development, actually). I wrote down my specifications, then alternated writing tests, then code, writing the code to pass the latest ...
Benjamin's user avatar
  • 131
5 votes
4 answers
2k views

I know what IllegalStateException is for, but I wonder if in some cases I should actually use it or it's just a matter of design. Let's say I have a Tournament class that models a sports tournament ...
dabadaba's user avatar
  • 2,266
2 votes
2 answers
1k views

Imagine this simple application use case, say, for fetching data from outisde of the app. These steps represent the "depth" of the layers, from top to bottom. UI touch event ViewModel handles said ...
Gil Sand's user avatar
  • 2,193
10 votes
2 answers
3k views

I am new to Java and was reading its documentation on exceptions., and especially the Unchecked Exceptions — The Controversy page. The bottom-line says: If a client can reasonably be expected to ...
ABcDexter's user avatar
  • 209
4 votes
3 answers
2k views

As someone used to C++ and new to JavaScript, I find this behavior odd. Whether a program runs directly on the platform like C++ ones, or it runs at a higher (or deeper?) level like JavaScript ones, ...
vin's user avatar
  • 384
3 votes
3 answers
719 views

Let us consider the following C# code as an example: public static string GetCurentExecutableDirectory() { return System.IO.Path.GetFullPath( System.Reflection.Assembly....
Marsya Kaustentein's user avatar
20 votes
5 answers
3k views

The isocpp.org exception FAQ states Do not use throw to indicate a coding error in usage of a function. Use assert or other mechanism to either send the process into a debugger or to crash the ...
cooky451's user avatar
  • 301
-1 votes
5 answers
5k views

I'm doing some cleanup operations that could throw an exception, and I want to implement the logic of a finally block, but only if no exceptions are thrown: The initial implementation is this: ...
thecoop's user avatar
  • 539
3 votes
2 answers
2k views

Is it wrong to add fields to exceptions? I have a problem that happens and I'm thinking of adding considerable information to an exception, but it sounds weird: an exception with getters. What you ...
user3452444's user avatar
15 votes
3 answers
30k views

I use @SuppressWarnings("unchecked") and @SuppressWarnings("null") mostly above methods to let the code compile without any warnings but I have my doubts. Found this Stackoverflow question. Jon Skeet ...
Bilesh Ganguly's user avatar
2 votes
3 answers
812 views

I really like the concept of assertions in Java in the way how to use them. It's much easier than to write an if and then throw an Exception/Error. But the thing I don't understand is, why do they ...
piegames's user avatar
  • 261
3 votes
2 answers
156 views

So, I was thinking about writing custom exceptions today, and considered the invalid operation exception. This exception can mean many many things, and in some actions, the operations might be invalid ...
Sidney's user avatar
  • 181
4 votes
3 answers
3k views

Consider the below method- public void operationOnList(List<String> list) { list.add(1); } It is obvious that if list is null this method will throw a NullPointerException. My question is ...
rents's user avatar
  • 173
1 vote
1 answer
11k views

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 ...
hex's user avatar
  • 111
1 vote
2 answers
1k views

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 list,...
WhiteHotLoveTiger's user avatar
16 votes
5 answers
5k views

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 ...
Ortund's user avatar
  • 393
3 votes
5 answers
2k views

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. ...
Natjo's user avatar
  • 141
6 votes
2 answers
459 views

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 is ...
Noel Yap's user avatar
  • 171
17 votes
11 answers
6k views

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 ...
x2bool's user avatar
  • 281
-3 votes
1 answer
218 views

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 ...
user2638180's user avatar
1 vote
1 answer
694 views

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 own ...
Snoop's user avatar
  • 2,758
2 votes
1 answer
539 views

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 ...
RubberDuck's user avatar
  • 9,021
0 votes
1 answer
223 views

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 ...
serv-inc's user avatar
  • 225
-1 votes
2 answers
1k views

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. ...
Rajeev's user avatar
  • 555
6 votes
4 answers
16k views

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 ...
dwjohnston's user avatar
  • 2,769
3 votes
4 answers
630 views

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 ...
Zymus's user avatar
  • 2,553
2 votes
2 answers
205 views

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, ...
caarlos0's user avatar
  • 259
2 votes
3 answers
1k views

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 ...
user4205580's user avatar
0 votes
2 answers
1k views

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 ...
bigcodeszzer's user avatar
3 votes
1 answer
875 views

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 ...
Snoop's user avatar
  • 2,758
6 votes
2 answers
2k views

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? ...
konishiki's user avatar
  • 475
4 votes
1 answer
294 views

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 ...
CHendrix's user avatar
  • 534
3 votes
2 answers
1k views

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, ...
evanjdooner's user avatar
3 votes
0 answers
316 views

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 ...
donquixote's user avatar
2 votes
2 answers
4k views

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 ...
hgiesel's user avatar
  • 831
5 votes
4 answers
7k views

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 ...
Jorge Campos's user avatar
45 votes
8 answers
5k views

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 ...
RaidenF's user avatar
  • 1,579
7 votes
2 answers
7k views

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 ...
ChrisD's user avatar
  • 191
1 vote
1 answer
95 views

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 ...
Gil Sand's user avatar
  • 2,193
13 votes
2 answers
4k views

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 ...
patrik's user avatar
  • 386
29 votes
7 answers
12k views

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 ...
Praxeolitic's user avatar
  • 1,674
1 vote
1 answer
214 views

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 ...
cat's user avatar
  • 734

1
3 4
5
6 7
13