try-catch

Does Javascript fire an event for unhandled/uncaught exceptions?

I'm looking to log unhandled javascript exceptions. Is there an event that fires when an exception isn't caught? I'm looking to catch the exceptions before they cause javascript errors in the browser, but I'd rather not run my entire application inside of a try/catch. Any help would be appreciated. Thanks! Update: tvanfosson pointed ou...

Will code in a Finally statement fire if I return a value in a Try block?

I'm reviewing some code for a friend and say that he was using a return statement inside of a try-finally block. Does the code in the Finally section still fire even though the rest of the try block doesn't? Example: public bool someMethod() { try { return true; throw new Exception("test"); // doesn't seem to get executed ...

Finally in C++

Is this a good way to implement a Finally-like behavior in standard C++? (Without special pointers) class Exception : public Exception { public: virtual bool isException() { return true; } }; class NoException : public Exception { public: bool isException() { return false; } }; Object *myObject = 0; try { // OBJECT CREATIO...

What exactly is "Abrupt completion of a finally clause"?

According to the Java Language Specification: If there are any enclosing try statements whose try blocks contain the throw statement, then any finally clauses of those try statements are executed as control is transferred outward, until the thrown value is caught. Note that abrupt completion of a finally clause can disrupt the transf...

C# Do I need TRY/CATCH in order to throw?

If all I want to do is throw the exception up a level when it occurs? private void TryCatch() { try { foo(); } catch (Exception ex) { throw; } } private void NoTryCatch() { foo(); } Aren't these two methods the same? If an exception occurs in TryCatch it will be thrown up a level and if an except...

Is it bad practice to return from within a try catch finally block

So I came across some code this morning that looked like this: try { x = SomeThingDangerous(); return x; } catch (Exception ex) { throw new DangerousException(ex); } finally { CleanUpDangerousStuff(); } Now this code compiles fine and works as it should, but it just doesn't feel right to return from within a try block,...

throws Exception in finally blocks

Is there an elegant way to handle exceptions that are thrown in the a finally block? For example: try { // Use the resource. } catch( Exception ex ) { // Problem with the resource. } finally { try{ resource.close(); } catch( Exception ex ) { // Could not close the resource? } } How do you avoid the try/catc...

How can I catch the output from a carp in Perl?

I am writing a Perl module, and I am using carp to throw a non-fatal warning back to the calling program. The carp warning works fine - I am checking if an input parameter meets a certain condition - if it does not meet the condition, a warning is sent with carp and the module continues on using a default for the parameter instead of th...

Is there a favored idiom for mimicing Java's try/finally in C++ ?

Been doing Java for number of years so haven't been tracking C++. Has finally clause been added to C++ exception handling in the language definition? Is there a favored idiom that mimics Java's try/finally? Am also bothered that C++ doesn't have an ultimate super type for all possible exceptions that could be thrown - like Java's Throw...

Handling exceptions vs. Preventing them from occuring in the first place - C#

I have a asp:BoundColumn with DateTime? data (i'll call it column X) in the asp:GridView. I loop through all the rows in the grid, and cast the .Text property to column X to DateTime (i need this to do some checking and change the cell background color if needed). I have 2 options: wrap the cast in try/catch ... handle FormatException...

Catching c++ base exceptions

In my project we have a base exception. For handling showing error dialogs, log and such. Im looking for a way to handle all derived classes of that exception, I thought this would work: try { main_loop(); } catch (const MyExceptionBase* e) { handle_error(e); } As every child instance thrown could be represented by a pointer to it...

Create trigger with try...catch in SQL Server 2005

Hello, I've implemented the following trigger: CREATE TRIGGER [OnContactDeleted] ON [TABLE].[Contact] INSTEAD OF DELETE AS BEGIN SET NOCOUNT ON /*Store contact ID to variable*/ Update [TABLE].[Account] Set [PrimaryContactID] = null where [TABLE].[Account].[PrimaryContactID] = (Select ContactID fr...

Javascript: What's more efficient, IF block or TRY/CATCH?

I'd love some other opinions on what's more efficient in this code. Basically in the following code, there's a setInterval loop and I need 4 requirements to be true before the code runs in the loop. So in v.1 I wrote an if statement checking all 4. Worked fine. Then I switched to just using try/catch, with the code I want to execute sit...

SQLServer try catch performance

Has anyone found any performance boost/tradoff of using BEGIN TRY..END TRY in sql server 2008, vs the old IF @@ERROR <> 0? Just curious to know if there are performance penalties or not. ...

How do I catch system-level exceptions in Linux C++?

The following catch() is not called: void test(void) { int i=1,j=0,k; try { k = i/j; } catch(...) { ...handle it... } } Is there a way to catch this kind of exception? ...

Is it ok to rely on a try-catch in a CreateOrUpdate method for the Entity Framework?

Is it acceptable to do this? First try to the add the entity. If the add fails, it doesn't matter because that means the entity already exists? Or is there a more elegant/easy solution? EntityFrameworkEntities dal = EntityDataModelHelper.GetEntityDataModel(); try { dal.AddToXXXXXX(xxxxxxx); } catch { } try { dal.SaveChange...

Problem with MessageBox.Show in catch

Hello, When I try to run the following code It causes an Unhandled Exception. After much tweeking with the code I found if commented out the MessageBox.Show line the problem goes away! Unusually I have used MessageBox.Show statments in other catch{ } segments in other parts of the code with no problems. My question is does anyone know wh...

Would you ever NOT catch an exception, or throw an exception that won't be caught?

I've dealt with instances where I would throw/rethrow an exception knowing that the code surrounding it would catch the specific exception. But is there any time you would want to throw an exception, knowing that it wouldn't be caught? Or at least, NOT catch an exception? Exceptions immediately halt the application unless their handle...

Resharper and the C# Catch Clause

I'm new to Resharper and I'm trying to understand why it seems to suggest: catch (Exception) { } for catch { } and catch { } for catch (Exception) { } I'm baffled. ...

Troubleshooting PDO: Error not caught when executing prepared statement

I have run into a problem using pdo because an error was not caught. The code is simple and works just fine, I´ll just include a sample to avoid confusion: $sql = 'INSERT INTO somedatetable (something) VALUES (:something) ON DUPLICATE KEY UPDATE something=:something' try { $stmt = $dbh->prepare($sql); $values = ...