16
votes
1answer
517 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
2answers
226 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 ...
5
votes
4answers
591 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
434 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
367 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(); } ...
2
votes
1answer
284 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
233 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 ...
1
vote
3answers
202 views

When is a catch clause empty [duplicate]

I saw lots of questions and explanations regarding empty catch clauses but I was never actually sure what "empty" means. Is a catch clause like this empty? It clearly isn't empty for the eye because ...
1
vote
2answers
210 views

Wrapping specific checked exception in domain unchecked ones? [duplicate]

Uncle Bob says in Clean Code book that Unchecked Exceptions should be used. Now JDK has some checked exceptions: IOException, IllegalAccessException etc. which cannot be avoided. In my application ...
2
votes
7answers
458 views

better way to define an exception thrown by a method in Java?

I know how to define exceptions and all, but I'm not sure if the way I'm doing it is the most intuitive and readable by another users. I have a very simple method I've written that I want to throw an ...
7
votes
2answers
256 views

The suffix Exception on exceptions in java

Specifying a suffix of Exception on exception classes feels like a code smell to me (Redundant information - the rest of the name implies an error state and it inherits from Exception). However, it ...
3
votes
2answers
451 views

How to remove duplicate exception block code

I have good number of Service and DAO classes which has the same set of 30 line exception code block which gets repeated and it shows up in Code Duplication report. The approach which i can think of ...
6
votes
5answers
5k views

throwing runtime exception in Java application

I am working as a contractor designing enterprise Java application for my client in the role of a technical lead. The application will be used by end users and there will be a support team who will ...
52
votes
11answers
4k 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. ...
6
votes
2answers
841 views

Decision for Unchecked Exceptions in Scala

As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) ...
7
votes
4answers
600 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 ...
2
votes
3answers
661 views

Good practice or service for monitoring unhandled application errors for a small organization

I'm working with multiple software with varying ways of monitoring for errors. When I make software, I usually send email with the stack trace to admins(usually me). Some customer software is ...
1
vote
2answers
1k views

Exception hierarchy design

In my company we are building a webapp containing serveral central services that we design ourselves and then specify as interfaces. I.e. the interfaces are application specific and they are then ...
26
votes
5answers
2k views

Is use of finally clause for doing work after return bad style/dangerous?

As part of writing an Iterator, I found myself writing the following piece of code (stripping error handling) public T next() { try { return next; } finally { next = ...
15
votes
6answers
3k views

Efficient try / catch block usage?

Should catch blocks be used for writing logic i.e. handle flow control etc? Or just for throwing exceptions? Does it effect efficiency or maintainability of code? What are the side effects (if there ...
23
votes
4answers
9k views

Is it better to use assert or IllegalArgumentException for required method parameters?

In Java, which is more highly recommended, and why? Both types will throw exceptions, so in that regard handling them is the same. assert is slightly shorter, but I'm not sure how much that matters. ...
38
votes
7answers
19k 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 ...
4
votes
2answers
284 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 ...
3
votes
3answers
2k views

How to store exception messages

How are exception messages commonly stored? for any domain. I'm thinking about this from a maintenance standpoint. if(!Condition1) throw new Exception("Some exception"); if(!Condition2) ...
2
votes
3answers
658 views

What do you think of this Exception handling practice

I'm working on a project that includes a lot of creating/manipulating and reading JSONObjects and arrays but not in a systematic way. So there is JSON code everywhere. It is ok for me except that ...
8
votes
9answers
772 views

Should security restrictions cause a service to return null or throw an exception?

I'm in a bit of a disagreement with a more experienced developer on this issue, and wondering what others think about it; our environment is Java, EJB 3, services, etc. The code I wrote calls a ...
21
votes
9answers
7k 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?
6
votes
5answers
3k views

Is it not a good practice to handle runtime exceptions in the code?

I am working on a Java application, and I see that Run time exceptions are handled in many places. For example, try { //do something }catch(NullPointerException e){ ...
21
votes
8answers
4k views

What to put in a try/catch? [duplicate]

Note on the question: this is not a duplicate, Efficient try / catch block usage? was asked after this one. The other question is the duplicate. I was wondering what was the best way to use ...
4
votes
3answers
446 views

Improving exception handling? [duplicate]

I am a newbie programmer and I recently started learning about exception handling in Java. I know what try, catch and finally blocks do, but I really need to understand how to use them well and where ...
10
votes
1answer
3k views

Why does Java exit with success after an uncaught exception?

Any time a Perl, Python, C++ or Tcl program halts with an unhandled exception, those language runtimes take care to register a non-zero exit code for the process. Even Eclipse-based programs return 1 ...
13
votes
8answers
2k views

In Java, what are checked exceptions good for?

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 ...
19
votes
12answers
2k views

How to teach Exception Handling for New Programmers?

How do you go about teaching Exception Handling to Programmers. All other things are taught easily - Data Structures, ASP.NET, WinForms, WPF, WCF - you name it, everything can be taught easily. With ...
4
votes
2answers
348 views

How much logging should I do at production for SQLExcpetions?

I'm writing a small database-centric application in Java Swing that will be used internally in a small company. I haven't much experience with developing production-level applications. I don't use an ...