Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
AnswerRe: Documentation Pin
Pete O'Hanlon10-Mar-10 2:44
mvePete O'Hanlon10-Mar-10 2:44 
GeneralMessage Closed Pin
10-Mar-10 2:55
stancrm10-Mar-10 2:55 
GeneralRe: Documentation Pin
Pete O'Hanlon10-Mar-10 3:03
mvePete O'Hanlon10-Mar-10 3:03 
GeneralRe: Documentation Pin
R. Giskard Reventlov10-Mar-10 3:16
R. Giskard Reventlov10-Mar-10 3:16 
AnswerRe: Documentation Pin
NickPace10-Mar-10 3:50
NickPace10-Mar-10 3:50 
Questionptz camera control Pin
sindhumahe9-Mar-10 23:57
sindhumahe9-Mar-10 23:57 
AnswerRe: ptz camera control Pin
CDP180210-Mar-10 1:00
CDP180210-Mar-10 1:00 
Question[SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard9-Mar-10 23:49
blackblizzard9-Mar-10 23:49 
Hi everyone.

This is a trivial question, but I can't find the answer anywhere (even though it's been asked before in these forums, but it wasn't solved in a way that satisfies me): is it possible to catch several hierarchically unrelated exceptions in the same catch block? By hierarchically unrelated I mean one isn't a subclass of the other, etc.

Basically, I'd like to do this:

try {
    // Code.
} catch (ExceptionType1, ExceptionType2) {
    // Exception handling. I want to handle both types of exceptions the same way.
}


Is it possible, or do I need to do it as follows?

try {
    // Code.
} catch (ExceptionType1) {
    handleMyException();
} catch (ExceptionType2) {
    handleMyException();
}

public void handleMyException() {
    // Exception handling. I want to handle both types of exceptions the same way.
}


I know Java allows the first format (ExceptionType1, ExceptionType2), but C# doesn't seem to like it. However, having to create a method each time this happens doesn't seem to promote code-cleanliness.

So... is it possible to do it as in Java?

Thanks!
modified on Wednesday, March 10, 2010 6:10 AM

AnswerRe: Catching several (hierarchically unrelated) exceptions in the same catch block Pin
#realJSOP10-Mar-10 0:07
mve#realJSOP10-Mar-10 0:07 
GeneralRe: Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard10-Mar-10 0:10
blackblizzard10-Mar-10 0:10 
AnswerRe: Catching several (hierarchically unrelated) exceptions in the same catch block Pin
Keith Barrow10-Mar-10 0:09
professionalKeith Barrow10-Mar-10 0:09 
GeneralRe: Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard10-Mar-10 0:12
blackblizzard10-Mar-10 0:12 
AnswerRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
AspDotNetDev10-Mar-10 12:47
protectorAspDotNetDev10-Mar-10 12:47 
GeneralRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard10-Mar-10 20:31
blackblizzard10-Mar-10 20:31 
GeneralRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
AspDotNetDev10-Mar-10 20:50
protectorAspDotNetDev10-Mar-10 20:50 
GeneralRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard10-Mar-10 21:10
blackblizzard10-Mar-10 21:10 
GeneralRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
AspDotNetDev10-Mar-10 21:55
protectorAspDotNetDev10-Mar-10 21:55 
GeneralRe: [SOLVED] Catching several (hierarchically unrelated) exceptions in the same catch block Pin
blackblizzard10-Mar-10 22:00
blackblizzard10-Mar-10 22:00 
QuestionSending email and keeping a copy on the server Pin
eyalbi0079-Mar-10 22:53
eyalbi0079-Mar-10 22:53 
AnswerRe: Sending email and keeping a copy on the server Pin
Gerrit44410-Mar-10 0:07
Gerrit44410-Mar-10 0:07 
AnswerRe: Sending email and keeping a copy on the server Pin
DX Roster10-Mar-10 0:24
DX Roster10-Mar-10 0:24 
GeneralRe: Sending email and keeping a copy on the server Pin
Saksida Bojan10-Mar-10 5:42
Saksida Bojan10-Mar-10 5:42 
GeneralRe: Sending email and keeping a copy on the server Pin
eyalbi00714-Mar-10 0:18
eyalbi00714-Mar-10 0:18 
GeneralRe: Sending email and keeping a copy on the server Pin
Saksida Bojan14-Mar-10 2:04
Saksida Bojan14-Mar-10 2:04 
Questionaudio sound suite for .net crack Pin
Fatemi9-Mar-10 22:43
Fatemi9-Mar-10 22:43 

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.