Click here to Skip to main content
15,921,169 members
Home / Discussions / C#
   

C#

 
AnswerRe: Inserting image in header/footer of a word document Pin
Mohammad Dayyan12-Oct-08 0:14
Mohammad Dayyan12-Oct-08 0:14 
QuestionException Handling Question Pin
Rafone11-Oct-08 6:05
Rafone11-Oct-08 6:05 
AnswerRe: Exception Handling Question Pin
Pedram Behroozi11-Oct-08 6:14
Pedram Behroozi11-Oct-08 6:14 
AnswerRe: Exception Handling Question Pin
S. Senthil Kumar11-Oct-08 6:15
S. Senthil Kumar11-Oct-08 6:15 
AnswerRe: Exception Handling Question Pin
Giorgi Dalakishvili11-Oct-08 6:21
mentorGiorgi Dalakishvili11-Oct-08 6:21 
GeneralRe: Exception Handling Question Pin
Rafone11-Oct-08 8:35
Rafone11-Oct-08 8:35 
GeneralRe: Exception Handling Question Pin
Kevin McFarlane12-Oct-08 4:16
Kevin McFarlane12-Oct-08 4:16 
AnswerRe: Exception Handling Question Pin
Colin Angus Mackay11-Oct-08 6:22
Colin Angus Mackay11-Oct-08 6:22 
Rafone wrote:
Morning


It is early evening where I am.

Rafone wrote:
If I eliminate the throw new Exception(ex.Message); line I get an error


Without seeing the rest of your code I'm guessing here.

You have, I guess, declared tbl outside of the try/catch block. Something is assigned to it inside the try block.

When you throw the exception in the catch the compiler knows that return tbl will always have something assigned to it, because in all other instances you are exiting the method before it can return it.

Also, your code contains a bit of a WTF. At the end of your catch you have throw new Exception(ex.Message) - By doing that you are discarding all the information in the current exception (there is a lot more in there besides the message you know). You should retain that information so that you can debug things properly in the future. You have two strategies:

1. throw new Exception(ex.Message, ex);
or
2. throw;

In this situation option #2 is preferable because you are adding no value in #1.

Finally, don't catch Exception, use a specific exception type. Don't throw an Exception either, again, use a specific exception type. If a specific type does not exist then create one.


GeneralRe: Exception Handling Question Pin
Rafone11-Oct-08 8:44
Rafone11-Oct-08 8:44 
AnswerRe: Exception Handling Question Pin
Paul Conrad11-Oct-08 6:33
professionalPaul Conrad11-Oct-08 6:33 
AnswerRe: Exception Handling Question Pin
Rafone11-Oct-08 8:07
Rafone11-Oct-08 8:07 
AnswerRe: Exception Handling Question Pin
Pete O'Hanlon12-Oct-08 9:52
mvePete O'Hanlon12-Oct-08 9:52 
QuestionMemory Management Pin
Mogaambo11-Oct-08 5:58
Mogaambo11-Oct-08 5:58 
AnswerRe: Memory Management Pin
S. Senthil Kumar11-Oct-08 6:10
S. Senthil Kumar11-Oct-08 6:10 
QuestionUnsafe code Pin
dan!sh 11-Oct-08 5:56
professional dan!sh 11-Oct-08 5:56 
AnswerRe: Unsafe code Pin
Colin Angus Mackay11-Oct-08 6:08
Colin Angus Mackay11-Oct-08 6:08 
GeneralRe: Unsafe code Pin
dan!sh 11-Oct-08 6:12
professional dan!sh 11-Oct-08 6:12 
GeneralRe: Unsafe code Pin
Mark Churchill12-Oct-08 0:46
Mark Churchill12-Oct-08 0:46 
AnswerRe: Unsafe code Pin
S. Senthil Kumar11-Oct-08 6:18
S. Senthil Kumar11-Oct-08 6:18 
GeneralRe: Unsafe code Pin
dan!sh 11-Oct-08 6:21
professional dan!sh 11-Oct-08 6:21 
Questionout of memory exception Pin
Mogaambo11-Oct-08 5:50
Mogaambo11-Oct-08 5:50 
AnswerRe: out of memory exception Pin
Colin Angus Mackay11-Oct-08 6:11
Colin Angus Mackay11-Oct-08 6:11 
GeneralRe: out of memory exception Pin
Mogaambo11-Oct-08 10:13
Mogaambo11-Oct-08 10:13 
GeneralRe: out of memory exception Pin
Colin Angus Mackay11-Oct-08 12:01
Colin Angus Mackay11-Oct-08 12:01 
GeneralRe: out of memory exception Pin
Abi Bellamkonda12-Oct-08 14:34
Abi Bellamkonda12-Oct-08 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.