exception-handling

How can send back my own 404 error message in ASP.NET , but as json?

Hi folks, i'm trying to send back a simple error message as Json, with the HTTP code as 404. So i started out writing my own IExceptionFilter that checks to see the exception. To keep this simple, if the exception throw is of type ResourceNotFoundException then i set the code to 404. Otherwise everything else if 500. Now, the problem ...

How do I handle exceptions in a procedural language?

How do I do exception handling in a procedural language like C or Perl? (I know Perl also does OO.) What’s the best way to handle exception in procedural code in Perl? ...

Catching Unhandled Exceptions in Child Threads in WPF

I have a WPF application that spins off several threads. I have defined a DispatcherUnhandledException event handler in App.xaml.cs that displays a detailed error message, and this handler gets called every time the UI thread encounters an exception. The problem is with the child threads: their unhandled exceptions never get handled. How...

Will an exception get passed back to the calling method?

Let's say in one method I have try { callme(); } catch { // handle callme exception } Now let's say callme() calls method1() which in turn calls method2() -- If method2() throws an exception should it get thrown back to method1()'s frame, which will then stop any further execution inside of itself and pass the exception thrown from m...

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...

Order of exception handling stack frames on the call stack

What is the order in which exception handling stack frames are pushed onto the call stack in say C#. If i have a method: private void MyMethod() { try { DoSomething(); } catch (Exception ex) { //Handle } } Is a separate stack frame created for each exception handler as follows? DoSomething stackframe<br/> Exceptio...

Can I show an alert from Global.asax on a page that's experiencing a SQL Timeout?

In Global.asax, is there a way to handle SQL Timeouts elegantly, and display a message on the requesting page explaining the error? I know Global.asax has the Application_Error and Error events, but I'm not sure which (if any) I could use to accomplish this. Related, can I access the page instance which raised the error that Global.asa...

How much information in error messages to regular users?

I'm want to get an idea how I should handle end-user visible error messages in my web application. How much information do you give in error messages? Do you redirect all errors, regardless of type, to a common error page, or do you have a small set of pages (404, 403, all others)? Do you give error codes that the user could reference/...

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): ...

Confused about when to throw an exception

I am working on a library designed to communicate (over RS232 serial communication) with external devices. I was thinking about error handling strategy and exceptions seemed to be right and industry standard way of reporting errors. So I read few guidelines on exceptions. One pretty clearly states that I should not worry about performan...

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...

Ideas to debug and solve a very sporadic crash - appears to be an AV

Hi, I have a bug somewhere that is causing my app to just vanish without an error message or something like that. The app just dissapears from the screen and it's no longer listed on the Task Manager. The app is a C++Builder app (CBuilder2007), and I have tried everything I have think of to try to catch this error. It happens very very...

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...

.NET Catch General Exceptions

.NET Programming guidelines state that we should not catch general exceptions. I assume the following code is not very good because of the general exception type catch: private object CreateObject(string classname) { object obj = null; if (!string.IsNullOrEmpty(classname)) { try { ...

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_...

Hooking all function calls in JavaScript?

My intuitive response to this question would be ,"This is so stupid that I can't continue having this conversation." However: Is there any way to hook all javascript function calls within my module? I'd like to find a convenient way of showing "loading blah...", "done..." messages when performing AJAX calls without having to explicitly ...

MVC Exceptions within ModelState not being catched

I have noticed during some actions in MVC, such as an Edit ActionResult, if the UpdateModel fails it places the exception in to the ModelState, if I go through the collection I can find the exception. However there is no StackTrace information. So I have a few questions 1, How do I catch ModelState exceptions, in a generic way (ie on...

WPF global exception handler

Hi, sometimes, under not reproducible circumstances, my WPF application crashes without any message. The application simply close instantly. Where is the best place to implement the global Try/Catch block. At least i have to implement a messagebox with: "Sorry for the inconvenience ..." Any help would be most welcome, thank you. ...

Why IllegalArgumentException (JDK 1.4.2) cannot be constructed with a throwable cause ?

From a class extending java.beans.PropertyEditorSupport : /** * Sets the property value by parsing a given String. May raise * java.lang.IllegalArgumentException if either the String is * badly formatted or if this kind of property can't be expressed * as text. * * @param text The string to be parsed. */ public void setAsText(...

loading image from URL - How to capture the exception if the image is not there

My problem relates to the other question I have asked about loading image from the URL. The code below works. However, I have encountered the problem if I try to get the image (it suppose be there) but apparently was removed. The application does not know and returns the error. Is there a way to prevent it by capturing incoming error. ...