exception-handling

What is "throw"

Hi All, Can anyone please explain me use of throw in exception handling? What happens when i throw an exception? ...

Is "Dying is Awesome" preferred?

Recently I attended Jeffrey Richter's training courses about .NET. He mentions one strategy of coding "Dying is awesome". That is, don't write "catch (Exception ex)" even at the root of program or event loop. If some exception thrown that is not handled, just let the process die. I'm not sure this is right. Personally, I prefer to have...

Unhandled ThreadAbortException occuring - sometimes

Hello! I have a dialog that has to process large quantaties of data (the procedure is quite time consuming - first the ODBC fill takes its time, then the data processing kicks in) and the result is that the Form becomes unresponsive. This is not a problem really, it is enough to just open a "loading screen" in a new thread to notify the...

What is the best practice for exception handling in silverlight?

In ASP.NET, I usually log exceptions server-side, I win forms I can either log exceptions server-side or write to a log file on the client. Silverlight seems to fit somewhere in between. I wanted to know what everyone else is doing to handle their Silverlight exceptions and I was curious if any best practices have emerged for this y...

In .NET, what if something fails in the catch block, will finally always get called?

Hi, In a try/catch/finally block like: try { } catch() { // code fails here } finally { } So if there is an exception in the catch block, will finally always get called? What if there is no finally, will the code after the catch block get run? ...

Unhandled Exceptions with Global.asax

I am emailing unhandled exception details from global.asax. How can I get the path and/or filename of the aspx file or assembly file where an exception was not handled. This info was showing up in the exception's stack trace when I was developing & testing. When I deployed the global.asax to production, this info is no longer showing up...

What is the best exception handling strategy within error logging classes?

I am writing an error logging set of classes which will log to file, event log etc. What exception handling should be performed within these classes? For instance, say I have a LogError method, which is called from exception handlers, and writes to file. What is considered the best thing to do, should an error occur? Obviously, I should ...

What do you think of the "Don't catch unexpected Exceptions" best practice?

I've read a lot of times that one should never blindly catch exceptions. Some people say it's ok to wrap your Main() into a catch block to display errors instead of just exiting (see this SO post for example), but there seems to be a consensus that you should never let your program running if something unexpected occurred, since it's in ...

Is there an unhandled exception handler in Java?

If i remember correctly in .NET one can register "global" handlers for unhandled exceptions. I am wondering if there is something similar for Java. ...

how to handle exceptions in C# DLL loaded by C++

I have a DLL that is created in C# for the purpose of providing a COM interface to a third-party C# library. I have a C++ program that uses that COM interface so that it can communicate with the C# library. Sometimes, exceptions get thrown on the C# side and all I get back on the C++ side is an HRESULT from the COM invocation that says...

Handle URI hacking gracefully in ASP.NET

I've written an application that handles most exceptions gracefully, with the page's design intact and a pretty error message. My application catches them all in the Page_Error event and there adds the exception to HttpContext.Curent.Context.Items and then does a Server.Transfer to an Error.aspx page. I find this to be the only viable so...

How to handle exceptions during an ASP.NET request lifecycle

This question is kind of related to Handle URI hacking gracefully in ASP.NET in that it's too about how to best handle exceptions that occur during an ASP.NET request lifecycle. I've found a way to handle most exceptions gracefully, but then I've found that some exceptions occur so late in the request that there's no way to do stuff like...

Cheap exception handling in Python?

I read in an earlier answer that exception handling is cheap in Python so we shouldn't do pre-conditional checking. I have not heard of this before, but I'm relatively new to Python. Exception handling means a dynamic call and a static return, whereas an if statement is static call, static return. How can doing the checking be bad and ...

Situations for using exceptions, should user be able to trigger exceptions?

Is it acceptable or sensible to use exceptions to deal with user generated errors? Such as ... try { $job->authorise($user); } catch (InsufficentCreditException $e) { return E_INSUFFICIENT_CREDIT; } catch (PermissionDeniedException $e) { return E_PERMISSION_DENIED; } or are e...

how to time-out gracefully while downloading with python

I'm downloading a huge set of files with following code in a loop: try: urllib.urlretrieve(url2download, destination_on_local_filesystem) except KeyboardInterrupt: break except: print "Timed-out or got some other exception: "+url2download If the server times-out on URL url2download when connection is just initiating, the l...

How do I 'globally' catch exceptions thrown in object instances.

I am currently writing a winforms application (C#). I am making use of the Enterprise Library Exception Handling Block, following a fairly standard approach from what I can see. IE : In the Main method of Program.cs I have wired up event handler to Application.ThreadException event etc. This approach works well and handles the applicat...

ThreadAbortException vs graceful event handle exit in C#.

When aborting the execution of a thread I'm always doubting between a graceful exit with an event handler like this: int result = WaitHandle.WaitAny(handles); if (result = WAIT_FINALIZE) FinalizeAndExit(); and using the event to signal the thread it must terminate or just handling the ThreadAbortException to finalize the thread... ...

Databound numericupdown 'hiding' exceptiong thrown in bound property

I am having an issue where an exception being thrown from within a properties set accessor is not being caught by my global exception handler. I was having the issue in a larger application and after much gnashing of teeth troubleshooting the issue I tried, and succeeded in, replicating the issue in a simpler project. Following is the ...

How to pop up alert when HTTP connection fails on iPhone?

I want to write some code to handle exceptions when HTTP connection fails. I use the following codes: -(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error { UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle: [error localizedDescription] message: [error localizedFailureReaso...

Question about HTTP exception handling on iPhone

I try to add a method to handle exception, but the program just crashes instead of pop up an AlertView. 1) I set up the connection: -(void)connect:(NSString *)strURL { NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:strURL] cachePolicy:NSURLRequestUseProtocolCachePolicy ...