exception-handling

Is this a php bug, or is something wrong with my timezone/PHP settings?

The real, full contents of the file: <?php error_reporting(E_ALL); ini_set(display_errors, 'on'); try { //$x = strtotime('blah'); $x = new DateTime('lol'); } catch ( Exception $e ) { echo $e->getMessage(); } The DateTime constructor accepts a string, which should throw an exception if it can't parse it. This runs f...

Where should exceptions be caught and handled in a WPF application?

We have exception catching code in most of our event handlers etc, this leads to very complex logic, with flags that are set to say if there has been an exception so as not do the next step etc. At first sight I would move all exception report/logging to the AppDomain.UnhandledException event, however from my experience with WinForms th...

How can I improve this exception retry scenario?

I have a web service method I am calling which is 3rd party and outside of my domain. For some reason every now and again the web service fails with a gateway timeout. Its intermittent and a call to it directly after a failed attempt can succeed. Now I am left with a coding dilemma, I have code that should do the trick, but the code lo...

Getting the name which is not defined from NameError in python.

Hello! As you know, if we simply do: >>> a > 0 Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> a > 0 NameError: name 'a' is not defined Is there a way of catching the exception/error and extracting from it the value 'a'. I need this because I'm evaluating some dynamically created expressions, and woul...

eagerly evaluating boolean expressions in Python

Hi! Is there a way (using eval or whatever) to evaluate eagerly boolean expressions in python? Let's see this: >>> x = 3 >>> 5 < x < y False Yikes! That's very nice, because this will be false regardless of y's value. The thing is, y can be even undefined, and I'd like to get that exception. How can I get python to evaluate all expre...

How should I handle exceptions that are thrown during asynchronous methods that I've made syncrhonous? (or, Is this a code smell?)

I'm writing a synchronous method that calls an asynchronous method on another server. The server's method calls a callback when it's done, and in case of error one of the callback's arguments contains an exception. I'd like to throw an exception from my method, with the server's exception as its InnerException. However, in order to ca...

Throwing exception or retuning value

I am using another service in a Service Oriented Architecture. My service used the other service to save data into the database. Is is good practice for me to rethrow the exception which i get from save service or should i catch the exception and encapsulate it in my result and then just send the result back. ...

Handling Constraint SqlException in Asp.net

Hello, Suppose I have a user table that creates strong relationships (Enforce Foreign Key Constraint) with many additional tables. Such orders table .. If we try to delete a user with some orders then SqlException will arise.. How can I catch this exception and treat it properly? Is this strategy at all? 1) first try the delete actio...

Why Java return statment inside the catch block not working?

Why does the following code always return true even when an exception is thrown? public boolean write (ArrayList<String> inputText, String locationToSave) { try { File fileDir = new File(locationToSave); Writer out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(fileDir), "utf8")); ...

Can't determine what is throwing a NullPointer exception.

I have a method that looks like this: try { doStuff(); } catch (Exception ex) { logger.error(ex); } (I don't really use method names like doStuff - this is just to make things easy) In doStuff I do a variety of things, among them is call a data access method (so, another method within doStuff) that ends with the following: } cat...

try- catch. Handling multiple exceptions the same way (or with a fall through)

There has already been a question posted here which is very similar. Mine is extending that question a bit more. Say you want to catch multiple types of exception but want to handle it the same way, is there a way to do something like switch case ? switch (case) { case 1: case 2: DoSomething(); break; case 3: DoSomethingEls...

null reference exception was unhandled by user code

sir, i develop the following code in vs2005, now i just using this module in my new project @ vs 2008.. But this error was araised. I cant able to fix this problem... Private Sub DataAccess() Dim errHandle As New ErrorHandler Dim lobjCommon As New eCopsCommonFunctions Try AccessCodeDrplst.DataSource = ...

Garbage collection of object after exception

I have observed that after an exception I have an object for which constructor is not called, which causes a lock to be held. What is the best way to improve the situation? Would calling del in an except block be the solution? b=BigHash(DB_DIR, url) meta = bdecode(b.get()) return meta b holds a lock which is released on destruction (i...

Exception Handling Question

Hi All, I have a question regarding exception handling. Consider following Java code snippet. try{ //code }catch(SubSubException subsubex){ //code }catch(SubException subex){ //code }catch(Exception ex){ //code } I know this is the recommended wa...

If I catch exceptions inside a using statement for a SqlConnection, does the using still handle closing and disposing my connection?

I'm going through some old C#.NET code in an ASP.NET application making sure that all SqlConnections are wrapped in using blocks. This piece of code used to open cn and da and close and dispose them in both the catch block and the end of the method. I added the usings and can't figure out for certain if the using blocks still handle dis...

How to catch exception thrown while initializing a static member

I have a class with a static member: class MyClass { public: static const SomeOtherClass myVariable; }; Which I initialize in the CPP file like so: const SomeOtherClass MyClass::myVariable(SomeFunction()); The problem is, SomeFunction() reads a value from the registry. If that registry key doesn't exist, it throws an exception...

Is it ok to catch all exception types if you rethrow them wrapped another exception?

I know you're not suppose to write code that caches all exception types like this. try { //code that can throw an exception } catch { //what? I don't see no } Instead you're suppose to do something more like the code below allowing any other exception that you didn't expect to bubble up. try { //code that can throw an exception ...

UnauthorizedAccessException vs SecurityException

The MSDN constructor for a FileStream says that it may throw either an UnauthorizedAccessException or a SecurityException. Here's what MSDN says about these exceptions. UnauthorizedAccessException: The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error. Security...

addShutdownHook and setUncaughtExceptionHandler doesn't work as expected in java

I have a multi-threaded program, where I have one thread to watch over several threads. The functioning is designed like this: Main program does initiation and starts Watcher Thread, in void Main(), I have the line Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownThread(), "Exit Listener")); When I don't start the watcher ...

Can you catch an exception by the type of a conversion operator?

I don't know how to phrase the question very well in a short subject line, so let me try a longer explanation. Suppose I have these exception classes: class ExceptionTypeA : public std::runtime_error { // stuff }; class ExceptionTypeB : public std::runtime_error { // stuff operator ExceptionTypeA() const; // conversion op...