The tag has no wiki summary.

learn more… | top users | synonyms

3
votes
4answers
192 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 ...
1
vote
0answers
29 views

Multiple handlers of an exception, and handling exceptions in the UI

Related to: Is onError handler better than exceptions? Premise I am writing a piece of library code that performs certain tasks, to separate concerns, we decided it should not write to a log or ...
2
votes
2answers
72 views

What kind of exception to ask for out of range arguments?

What type of exception should I throw? I have a console class which describes rectangle of cells which a user can index by passing in a coordinate: width, height = 80, 25 console = ...
4
votes
4answers
220 views

Is it OK to let invalid arguments slip to another method?

For example lets take this method: public List<string[]> ReadAll(int listCapacity) { List<string[]> list = new List<string[]>(listCapacity); while (Read()) { ...
8
votes
3answers
1k views

“how bad” is unrelated code in try-catch-finally block?

This is a related Q: Is use of finally clause for doing work after return bad style/dangerous? In the referenced Q, the finally code is related to the structure used and the necessity of ...
0
votes
2answers
133 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 ...
24
votes
11answers
9k views

Is using nested try-catch blocks an anti-pattern?

Is this an antipattern? It is an acceptable practice? try { //do something } catch (Exception e) { try { //do something in the same line, but being less ambitious ...
54
votes
8answers
6k views

Exceptions: Why throw early, why catch late?

There are many well-known best practices about exception handling in isolation. I also know the do and don'ts very well, but I search for a best practices or patterns in larger environments, ...
0
votes
0answers
47 views

Using Statement lambda in exception handling

Following is a code snippet from MVP Win Forms application and this explanation would be helpful when answering the questions. My DAL doesn't handle exceptions and it will be propagated up to the ...
1
vote
1answer
63 views

Exception handling in WIn Forms application

When handling exceptions for example in a method in my presentation logic, is it ok to catch all possible exceptions in a one catch block as follows if the only purpose here is alerting the user. ...
1
vote
1answer
49 views

DAL Exception handling in a MVP application

In a MVP win forms application I'm handling exceptions as follows in DAL. Since the user messaging is not a responsibility of DAL, I want to move it in to my Presentation class. Could you show me a ...
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 ...
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 ...
2
votes
1answer
73 views

How to present domain model exceptions thrown through validation

In domain model of my web application I've an entity Foo which can be created only by a pojo FooBean: Foo.newInstance(FooBean fooBean) (Might have been better a Builder-pattern.) In the factory ...
0
votes
1answer
135 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
224 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 ...
11
votes
6answers
590 views

alternatives to nested try-catches for fallbacks

I have a situation where I am trying to retrieve an object. If the lookup fails I have several fallbacks in place, each of which may fail. So the code looks like: try { return ...
9
votes
4answers
244 views

Purposely raising exceptions to use catch

For a typical if...else wrapped with exception handling, is something like the following example a recommended practice to avoid code duplication? try { if (GetDataFromServer()) { ...
37
votes
8answers
7k views

Defensive Programming vs Exception Handling?

I'm working through the book "Head First Python" (it's my language to learn this year) and I got to a section where they argue about two code techniques: Defensive coding vs Exception handling. Here ...
16
votes
1answer
893 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 ...
3
votes
4answers
288 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
867 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
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 ...
3
votes
4answers
276 views

Using configuration to determine whether to handle exception or bubble it up

On a side project I'm working on I came up with a way of handling exceptions that's adjustable by configuration. So a try/catch block might look like this: try { fileHelper.MoveFile(file, ...
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 ...
-5
votes
1answer
102 views

I don't know why my code can not handle exception, then skip and continue execute the rest of programm [closed]

Scanner input = new Scanner(new File("grades.txt")); ArrayList<Integer> list = new ArrayList<Integer>(); Grade g = new Grade(); int b = 0; while (input.hasNext() ...
12
votes
5answers
558 views

Exception handling in a program that needs to run 24/7

I have read that we should only catch exceptions that can be handled, which makes catching the base exception class (C# in this case) a bad idea (on top of other reasons). I am currently part of a ...
3
votes
2answers
121 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 ...
1
vote
2answers
122 views

Should I Aggregate Web API Errors?

The Situation We are writing a REST API that performs validation up-front. The code is written such that it tries to find as many errors as possible. However, each error might correspond to a ...
38
votes
7answers
23k views

Why use try … finally without a catch clause?

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do ...
7
votes
4answers
377 views

What are good ways of balancing informative exceptions and clean code?

With our public SDK, we tend to want to give very informative messages about why an exception occurs. For example: if (interfaceInstance == null) { string errMsg = string.Format( ...
2
votes
1answer
114 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. ...
3
votes
1answer
126 views

I have a unexceptional exception. That is thrown by a API used in my project. Is it standard to log errors like these or handle them without logging [duplicate]

The API has a Throttle on the number of requests you can make. So we queue our requests in a local database and make as many requests as possible until the "Throttle exception" is thrown. Upon ...
5
votes
3answers
566 views

Authoritative sources for exception handling best practices [closed]

My work place suffers from a bad case of the Pokemon Exception Handling anti-pattern with constructs like the following splattered across the code base: try { ... } catch (Exception ex) { // ...
38
votes
7answers
2k 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 ...
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
355 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
125 views

What are the guidelines for either throwing an exception or failing silently for nonvalid arguments? [duplicate]

If you look at XContainer.Add(object content) method you can see that id does not require content to be not null. It just does nothing in case of null. However List.AddRange(IEnumerable collection) ...
-1
votes
2answers
429 views

Defensive Programming vs. Exception Handling [duplicate]

I have a question about defense programming and handling of exceptions. Here is a pseudo-code snippet first: try { // do some core logic; } catch (BadException e) { ErrorCode ec = ...
2
votes
1answer
316 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
1answer
407 views

Can AspectJ or AOP in general be used to test exception handling?

I'm reading a book's chapter ("Controlled Exception Test" in "Testing Object-Oriented Testing") about testing exception handling in a running system (not at unit level). The conclusion is that it is ...
1
vote
2answers
138 views

Understanding unit testing for dynamically changing condition

I was trying to understand how to write unit tests for a few days now. I'm confused with following scenarios in the existing code. In first function the max value changes depending on the object ...
2
votes
2answers
274 views

We need a custom strategy for collecting unhandled application exceptions. What are our options?

"Unhandled exception" term In .NET Framework, unhandled exceptions are the exceptions which were not handled by the application itself, and result in a crash. In a case of a desktop application, it ...
6
votes
2answers
336 views

Where should I handle fatal exceptions

Suppose I have a controller that loads a file and hands it over to the processing. Should I handle the exception in the file loader and return Null if something is wrong, or should I throw the ...
12
votes
5answers
864 views

Strengthening code with possibly useless exception handling

Is it a good practice to implement useless exception handling, just in case another part of the code is not coded correctly? Basic example A simple one, so I don't loose everybody :). Let's say I'm ...
22
votes
9answers
8k views

Is it good practice to catch a checked exception and throw a RuntimeException?

I read some code of a colleague and found that he often catches various exceptions and then always throws a 'RuntimeException' instead. I always thought this is very bad practice. Am I wrong?
8
votes
8answers
863 views

Using a try-finally (without catch) vs enum-state validation

I have been reading the advice on this question about how an exception should be dealt with as close to where it is raised as possible. My dilemma on the best practice is whether one should use a ...
15
votes
5answers
4k views

should I throw exception from constructor?

I know I can throw exception from constructor in PHP but should I do it? For example, if a parameter's value is not as I expected it. Or should I defer throwing an exception till a method is invoked. ...
0
votes
1answer
131 views

Exception handling class: static or object-oriented?

I am working in a windows service (using VB.Net) for internal use of my department. When ever a certain type of exception (FooException for now on) is captured, I follow the same logic: Log the ...
1
vote
3answers
217 views

Am I handling my exceptions in a sensible manner?

I'm still restructuring the code I have been given to update on my current work project, and I've come to the point where I'm looking at how the code handles an 'exceptional' input, that doesn't ...