exception

Shutting down an ExecutorService

In Tomcat, I wrote a ServletContextListener which will start an ExecutorService during startup and terminate it when it is unloaded. I am following the example in the javadoc for ExecutorService public void contextDestroyed( ServletContextEvent sce ) { executor.shutdown(); try { executor.awaitTermination( 50, TimeUn...

Check registry permission without throwing exception

I have a piece of code like this try { RegistryKey regKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\xxxx\\yyyyy"); // more code } catch { } I don't like the use of the empty catch block. But, it's useful because if the user don't have permissions to access the Registry, nothing should be done. This piece of code ge...

Trigger error from within exception handler

Given that I have a custom PHP error handler already, does it make sense to define an exception handler as an "forwarder" like this: function exception_handler(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } set_exception_handler('exception_handler'); The idea is to utilize the already existing error handler to ha...

Rethrowing exceptions under different names? What's the standard practice?

Hi, currently I have this client code in my PHP MVC web app: try { BookMapper::insert($book); } catch (DbUniqueConstraintViolationException $e) { $errorList->addMessage($book . " already exists!"); } I'm wondering is it bad practice to refer to the low-level framework Db* exceptions to my client code? If so, should I adjust my mo...

How to catch exit() in embedded C++ module from python code ?

Hello, I am embedding a c++ library (binding done with SIP) in my python application. Under certain circonstances (error cases), this library uses exit(), which causes my entire application to exit. Is there a way to catch this event, or do I need to modify the library to handle error cases differently ? Thank you very much, ...

Webservice SocketException - Only Breaks On One Application

I have a few applications which use a single Web Service which resides on the same server as the applications. Why would only one of the applications have a problem connecting to a web service? And is there a way I can better diagnose exactly what the problem is with the connection? It won't even connect to a web service the applicatio...

@Secured throws AccessDeniedException although roles are correct

After solving all authentication related problems in my first Spring web application I'm now stuck with authorization. Configuration using @Secured annotations is pretty straight-forward so I don't think I made a mistake here. Additionally I'm using an Active Directory using the LDAP authentication provider and assign roles by AD groups...

Defensive Programming: Guidelines in Java

I’m from a .NET background and now dabbling in Java. Currently, I’m having big problems designing an API defensively against faulty input. Let’s say I’ve got the following code (close enough): public void setTokens(Node node, int newTokens) { tokens.put(node, newTokens); } However, this code can fail for two reasons: User passe...

What are good names for user defined exceptions?

This question covers a broad range of programming languages; however, I am specifically working with Python in this case. I would like to create some user defined exceptions, but I'm not sure how fine-grained they should be. For example, if I have the following class: class Race(object): def __init__(self, start_time, end_time): ...

Using bool (return Type) to handle exceptions or pass exception to client?

I am trying to find out the best way of handling exceptions, I have a number of layers to my application and started to use a return type of BOOL i.e. if it fails then return False and if it succeeds return True.. This works great in methods like SaveMyRecord(somerecord); as i am passing in values and don't require anything returned so...

What language was the first to implement exception handling?

This question is not a technical but a historical one. I was just thinking today that I've also thought of Java as the "first" language to use exception handling, until I realized that my reason for thinking this way is probably because Java was the first language I encountered that used it, but I had no historical data to back up that c...

What is a StackOverFlow exception in vb.net?

I dont even know what caused it in my application. What is it? I created a new instance of a class (the class was in another file), but at the first time I call a method it throws a StackOverFlow exception. The only thing that I think would logically throw a stackoverflow exception would be if someone downvoted Jon Skeet. But seriously...

Exception for missing data

I was wondering what kind of exception should one throw for missing data. For example if an xml node doesn't contain data. It would be easy to "throw new Exception(...)" but this is not recommended. Another option would be to create a new exception class like MissingDataException or InvalidDataException but isn't there a built-in excepti...

How can I avoid using exceptions in C++?

What techniques can I use to avoid exceptions in C++, as mentioned in Google's style guide? ...

WCF The service '/myservice.svc' activated due to an exception during compilation

Our current deployment strategy is to deploy all assemblies with each application / service but control where *.exe and service implementaion assemblies are deployed. With that in mind, I have a specific service that when I deploy 2 unreferenced resource assemblies I get a compilation error. System.IO.FileNotFoundException: Could not l...

Access to XMLHttpRequest.statusText will cause exception when it fails?

$.ajax(error:function(XMLHttpRequest, textStatus, errorThrown) { XMLHttpRequest.statusText }) Did someone also met this problem? EDIT I'm using Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2 ...

SPWeb disposing himself and causing exception

Hello. When trying to use SPWeb.GetSiteData(SPSiteDataQuery) (Trying to bind some data to SPGridView), it throws me an TargetInvocationException with a following stacktrace: Exception at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTyp...

Handling static constructor exceptions in a multithreaded application

I have a static class that creates several worker threads in its constructor. If an exception occurs before the workers have been created my Application.ThreadException handler (used to shut the app down if an error not known to be recoverable occurs) triggers normally and everything is fine. Once the first worker thread has been creat...

g++ problem: exception not caught

The situation is that I have a dynamic library written in C++ that is wrapped for Python by another dynamic library, also written in C++ (generated by SIP to be specific). The first dynamic library defines a function do_raise, which throws an exception RaiserError, a subclass of std::exception. The second dynamic library, in wrapping do_...

LINQ problems with NText, Text and Image on SQL server

Apologies up front, because this isn't a question but a solution - but it took a lot of searching to find out the answer and google wasn't much help, so I wanted to give something back to the community by providing the error and the solution to help future googlers. When using LINQ to SQL, I ran into a problem when submitting changes (t...