exception-handling

How to except SyntaxError?

I would like to except the error the following code produces, but I don't know how. from datetime import datetime try: date = datetime(2009, 12a, 31) except: print "error" The code above is not printing "error". That's what I would like to be able to do. edit: The reason I would like to check for syntax errors, is because 12...

Java: Good way to encapsulate Integer.parseInt()

I have a project in which we often use Integer.parseInt() to convert a String to an int. When something goes wrong (for example, the String is not a number but the letter 'a', or whatever) this method will throw an exception. However, if I have to put exceptions in my code everywhere, this starts to look very ugly very quickly. I would l...

Use of r1 stack pointer when handling external exception on PowerPC

I'm writing an assembler routine to handle the 0x500 external/decrementer exception in an EABI embedded PowerPC application. In my assembler routine called from the 0x500 vector point I want to use some memory to context save registers before branching to the handler function in 'C'. Because i) the exception model guarantees the previ...

When to check for nulls

This is kinda an open ended question but I'm trying to sharpen my skills with good practices in exception handling specifically when to check for nulls in general. I know mostly when to check for nulls but I have to say half the time I don't and that's bothering to me. I know ints cannot be set to null unless you use a nullable int. I...

.NET Unhandled Exception Dialog not Appearing

I'm working on a .NET 4.0 Beta 1 application. When the app its run without a debugger attached and there an unhandled exception occurs, the application crashes without never showing the Unhandled Exception dialog (the one that showed the callstack and the exception that was thrown). I understand this behavior is desirable in production...

Should a Perl constructor return an undef or a "invalid" object?

Question: What is considered to be "Best practice" - and why - of handling errors in a constructor?. "Best Practice" can be a quote from Schwartz, or 50% of CPAN modules use it, etc...; but I'm happy with well reasoned opinion from anyone even if it explains why the common best practice is not really the best approach. As far as my o...

.NET Remoting Exception not handled Client-Side

I checked the rest of the remoting questions, and this specific case did not seem to be addressed. I have a .NET Remoting server/client set up. On the server side I have an object with a method that can throw an exception, and a client which will try to call that method. Server: public bool MyEquals(Guid myGuid, string a, string b) { ...

What can cause Application_Error not to be invoked?

Hi guys, For the last 2 weeks I have a case that I can't figure it out, maybe you guys already passed through the same problem or ear/read about it and can help me. I have an ASP.NET Project that I run on my machine and other machines fine, every time I try to temper the QueryString I get an error that is been thrown by the System.Exce...

Catch initialization error in Ruby on Rails

What I want to do: redirect the user to a special error page if the database is down. I'm using an Oracle database with the OCI adapter. It appears that, if the database is unavailable (say, down for backup), that the OCI adapter throws an error before I ever hit a controller (based on the stack trace, it's while it's setting up the co...

Rails Exception Notification Plugin - Force send email

I'm using the Rails exception_notification plugin in my app and find it very useful. However, there are occasions when I want to catch an exception and deal with it gracefully but still would like to receive the exception notification email. It only seems to send for uncaught exceptions it seems. Does anyone know how to force send the ...

Log4J - how to log an exception caught in an imported library?

I am a pretty new user of Log4J v. 1.2.15, as a friend of mine convinced me of the advantages over console or other forms of logging. However, as i was doing some tests, i've encountered a test case that got me thinking. Here it is what i did : I've configured the properties, added 2 appenders, a ConsoleAppender and a RollingFileAppen...

When to log errors in ASPX when using database connections?

When to log errors in ASPX when using database connections? In the following code, the authors of Pro ASP.NET 3.5 in C# 2008 (Third ed), suggest logging an SQL error in the catch block. My questions are: Is this common practice? Is this the best practice? In short, would it be better to close the current connection and handle the erro...

Why does my new PowerPC interrupt handler crash only when caches are on

I'm using a PowerPC 750 and have just started experimenting with the external interrupt. I have an interrupt-driven mini program that works fine provided the data cache is off. If I turn the cache on then the PowerPC crashes on the first access to a memory-mapped peripheral after the external interrupt has fired. This surprises me bec...

Java - where and how should exceptions be used?

Hello. I was reading some things about exception handling in Java, to be able to write better code. OK, I admit, I am guilty; I've used too much try-catch{} blocks, I've used ex.printStackTrace() in the catch, not even using a proper logger (actually the System.out and System.err were redirected to a PrintWriter, so a log was generated)....

Problem with handling exception when sending data by ajax with jQuery

hello, i got following part of one of functions if(continiueSend) { $.ajax ({ type: "POST", url: "mailer.php", data: "somestestdata", timeout: 5000, success: function(a) { alert(a); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError);...

java: log exception being thrown

In java, I want to log the exception being thrown from a piece of code: try { doRiskyThing(); } catch(Throwable t) { log.warn("too bad"); throw t; } The problem is that now my method must declare it throws throwable. On the other hand, if I log the exception in a finally block, how do I know what exception is being thrown...

C#: How to mark a method will throw unconditionally?

Is there a way to decorate a method that will do some logging, then throw an exception unconditionally, as such? I have code like this: void foo(out int x) { if( condition() ) { x = bar(); return; } // notice that x is not yet set here, but compiler doesn't complain throw new Exception( "missed something." ); } If I try writi...

Sharepoint 2007 Web Part Exception Handling for Missing DLL references

I know that you can wrap problematic code in a try/catch block to prevent an error from taking out your webpart. But what can you do for missing references/dlls? Is there anyway of catching those errors before they blow up your SharePoint page? ...

how to apply "catch-all" exception clause to complex python web-scraping script?

Hi, I've got a list of 100 websites in CSV format. All of the sites have the same general format, including a large table with 7 columns. I wrote this script to extract the data from the 7th column of each of the websites and then write this data to file. The script below partially works, however: opening the output file (after running ...

How can I handle exceptions in a list comprehension in Python?

I have some a list comprehension in Python in which each iteration can throw an exception. For instance, if I have: eggs = (1,3,0,3,2) [1/egg for egg in eggs] I'll get a ZeroDivisionError exception in the 3rd element. How can I handle this exception and continue execution of the list comprehension? The only way I can think of is...