try-catch

Debugging an exception in an empty catch block

I'm debugging a production application that has a rash of empty catch blocks sigh: try {*SOME CODE*} catch{} Is there a way of seeing what the exception is when the debugger hits the catch in the IDE? ...

catching all types of exceptions in C++ in one catch block

in c++, Iam trying to catch all types of exceptions in one catch (like catch(Exception) in C#). how is it done ? and more, how can one catch devide-by-zero exceptions ? ...

Performance of try-catch in php

What kind of performance implications are there to consider when using try-catch statements in php 5? I've read some old and seemingly conflicting information on this subject on the web before. A lot of the framework I currently have to work with was created on php 4 and lacks many of the niceties of php 5. So, I don't have much experi...

C#: Try-catch every line of code without individual try-catch blocks

I do not currently have this issue, but you never know, and thought experiments are always fun. Ignoring the obvious problems that you would have to have with your architecture to even be attempting this, let's assume that you had some horribly-written code of someone else's design, and you needed to do a bunch of wide and varied operat...

Javascript Try/Catch

I've got a function that runs a user generated Regex. However, if the user enters a regex that won't run then it stops and falls over. I've tried wrapping the line in a Try/Catch block but alas nothing happens. If it helps, I'm running jQuery but the code below does not have it as I'm guessing that it's a little more fundamental than th...

Can SQL Try-Catch blocks handle thrown CLR errors?

We are using SQL 2005 and the try-catch functionality to handle all of our error handling within the DB. We are currently working on deploying a .NET CLR function to make some WCF calls in the DB. This WCF procedure is written in the CLR and then deployed to SQL. If I put a try-catch block in the CLR code, it catches the error fine. Howe...

Why is try {...} finally {...} good; try {...} catch{} bad?

I have seen people say that it is bad form to use catch with no arguments, especially if that catch doesn't do anything: StreamReader reader=new StreamReader("myfile.txt"); try { int i = 5 / 0; } catch // No args, so it will catch any exception {} reader.Close(); However, this is considered good form: StreamReader reader=new St...

Is a JavaScript try-catch ignoring an expected occasional error bad practice?

In JavaScript is it wrong to use a try-catch block and ignore the error rather than test many attributes in the block for null? try{ if(myInfo.person.name == newInfo.person.name && myInfo.person.address.street == newInfo.person.address.street && myInfo.person.address.zip == newInfo.person.address.zip) { this.set...

Should try...catch go inside or outside a loop?

I have a loop that looks something like this: for(int i = 0; i < max; i++) { String myString = ...; float myNum = Float.parseFloat(myString); myFloats[i] = myNum; } This is the main content of a method whose sole purpose is to return the array of floats. I want this method to return null if there is an error, so I put the ...

"TryParse / Parse like" pattern: what is the best way to implement it

This question is a follow-up from How to indicate that a method was unsuccessful. The xxx() Tryxxx() pattern is something that can be very useful in many libraries. I am wondering what is the best way to offer both implementations without duplicating my code. What is best: public int DoSomething(string a) { // might throw an excep...

Is there a preference for nested try/catch blocks?

One of the things that always bugs me about using Readers and Streams in Java is that the close() method can throw an exception. Since it's a good idea to put the close method in a finally block, that necessitates a bit of an awkward situation. I usually use this construction: FileReader fr = new FileReader("SomeFile.txt"); try { tr...

In C++ what are the benefits of using exceptions and try / catch instead of just returning an error code?

I've programmed C and C++ for a long time and so far I've never used exceptions and try / catch. What are the benefits of using that instead of just having functions return error codes? ...

Does Windows Powershell have a Try/Catch or other error handling mechanism?

In a script, when a command-let or other executable statement errors out, is there a try/catch type of mechanism to recover from these errors? I haven't run across one in the documentation. ...

SQL Server 2005 - Error_Message() not showing full message

I have encapsulated a backup database command in a Try/Catch and it appears that the error message is being lost somewhere. For example: BACKUP DATABASE NonExistantDB TO DISK = 'C:\TEMP\NonExistantDB.bak' ..gives error: Could not locate entry in sysdatabases for database 'NonExistantDB'. No entry found with that name. Make sure that ...

Is it legal and possible to access the return value in a finally block?

I wish to set a usererror string before leaving a function, depending on the return code and variable in the function. I currently have: Dim RetVal as RetType try ... if ... then RetVal = RetType.FailedParse end try endif ... finally select case RetVal case ... UserStr = ... end select end try ret...

How do exceptions work (behind the scenes) in c++

I keep seeing people say that exceptions are slow but I never see any proof. So instead of asking if they are I will ask how do exceptions work behind the scene so I can make a decisions of when to use them and if they are slow. From what I know exceptions are the same thing as doing a bunch of return but it also checks when it needs to...

How to handle multiple errors in C#?

Hi all, I have some code that reads 10 registry keys, sometimes the values are not present sometimes the keys are not present, sometimes the value isn't boolean etc etc. How should I add error handling to this, currently it is placed in one big try{} catch{} but if the second value I read fails then the rest are not read as the program ...

How do I wrap a function in Javascript?

I'm writing a global error handling "module" for one of my applications. One of the features I want to have is to be able to easily wrap a function with a Try{} Catch{} block, so that all calls to that function will automatically have the error handling code that'll call my global logging method. (To avoid polluting the code everywhere ...

Thorough use of 'if' statements or 'try/catch' blocks?

Give me some of your thoughts on which is a better coding practice/makes more efficient code/looks prettier/whatever: Increasing and improving your ability to use if statements to anticipate and catch potential problems? Or simply making good use of try/catch in general? Let's say this is for Java (if it matters). Edit: I'm presentl...

Can you really have a function/method without a body but just a try/catch block?

Note that this function does not have a "{" and "}" body. Just a try/catch block: void func( void ) try { ... } catch(...) { ... } Is this intentionally part of C++, or is this a g++ extension? Is there any purpose to this other than bypass 1 level of {}? I'd never heard of this until I ran into http://stupefydeveloper.blog...