javax.persistence.NoResultException: No entity found for query

Yes. You need to use the try/catch block, but no need to catch the Exception. As per the API it will throw NoResultException if there is no result, and its up to you how you want to handle it. DrawUnusedBalance drawUnusedBalance = null; try{ drawUnusedBalance = (DrawUnusedBalance)query.getSingleResult() catch (NoResultException nre){ //Ignore this because as per … Read more

When is it OK to catch a RuntimeException

You catch RuntimeException for the same reason that you catch any exception: You plan to do something with it. Perhaps you can correct whatever caused the exception. Perhaps you simply want to re-throw with a different exception type. Catching and ignoring any exception, however, is extremely bad practice.

Catching multiple exceptions at once in Scala

You can bind the whole pattern to a variable like this: try { throw new java.io.IOException(“no such file”) } catch { // prints out “java.io.IOException: no such file” case e @ (_ : RuntimeException | _ : java.io.IOException) => println(e) } See the Scala Language Specification page 118 paragraph 8.1.11 called Pattern alternatives. Watch Pattern … Read more

Design patterns: exception / error handling

These patterns and best practices are often bound to a specific platform/language, so they are the first place to look for them. Exception patterns wiki is a general patterns resource. As an example check the following links for java: Best Practices for Exception Handling 15 Best practices about exception handling Exception-Handling Antipatterns Going through such … Read more

If you’re in the “we don’t use exceptions” camp, then how do you use the standard library?

I will answer for myself and my corner of the world. I write c++14 (will be 17 once compilers have better support) latency critical financial apps that process gargantuan amounts of money and can’t ever go down. The ruleset is: no exceptions no rtti no runtime dispatch (almost) no inheritance Memory is pooled and pre-allocated, … Read more

VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows

This is a nasty problem induced by the wow64 emulation layer that allows 32-bit code to run on the 64-bit version of Windows 7. It swallows exceptions in the code that runs in response to a notification generated by the 64-bit window manager, like the Load event. Preventing the debugger from seeing it and stepping … Read more

Using Global Exception Handling on android

Basic Example for someone who comes to this page with a solution 🙂 public class ChildActivity extends BaseActivity { @SuppressWarnings(“unused”) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int a=1/0; } } Class for handling error: public class BaseActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread paramThread, … Read more

Re-throwing exception in NodeJS and not losing stack trace

I’m not aware of a native method like Java’s and I’ve not found an elegant solution for wrapping errors yet. The problem with creating a new Error is you can lose metadata that was attached to the original Error that was thrown, the stack trace and type are generally the important items lost. Making modifications … Read more