Click here to Skip to main content
14,540,528 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

i have problem when catching my exception thrown from other DLL library.

here is my code,

throw new FaultException<ArgumentException>(new ArgumentException("my message", errorMessage), errorMessage);


how can i catch this exception ?

something like

catch(System.ServiceModel.FaultException<ArgumentException>)
but it won't work.

thanks
-Amit.
Posted
Updated 13-Dec-11 20:18pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use
catch(FaultException<ArgumentException> exception) { /*...*/ }

General syntax always works; you only should understand that the type is always some instantiated type FaultException<ArgumentException>. As to FaultException, this is not exactly a type, this is a generic type, not instantiated.

[EDIT]

"It did not work" is not a valid issue report. I just gave you a valid way to catch an exception of a certain type, which always work. Any useful advice can work if you understand where to use it, not that you catch something-which-should-not-be-named in a catch block who-knows-there, as you can experience endless problems without really understanding what's going on. You should always run your code under debugger in the settings where you can get all the information you need.

To start with, you can catch all exceptions on top of the stack of each thread and, say, put a break point on every handler. When exception is caught, you should examine its exact type. Importantly, you need to look at Exception.Stack: this is just a string; and, if debug information was available during the run, if will show you all the file names and line numbers where the exception was thrown/propagated to the point you are stopped in. Looking this information, you can untie the whole history of what happened.

—SA
   
v2
Comments
AmitGajjar 14-Dec-11 2:48am
   
Hi, i already done it but didn't work,
AmitGajjar 14-Dec-11 4:31am
   
Thanks for help, actually its bug of third party code that i am using... thanks a lot...
Sergey Alexandrovich Kryukov 14-Dec-11 10:44am
   
Wait a minute...
--SA
Sergey Alexandrovich Kryukov 14-Dec-11 10:55am
   
Don't work blindfolded, investigate what's going on, get a complete picture. Please look at my updated answer above, after [EDIT].
--SA
AmitGajjar 14-Dec-11 23:04pm
   
Hi SA,

thanks for the information, but in one of my third party DLL function call i am expecting ArgumentException and even in their code they have written that but before reach at that line other exception occur that is my actual problem.

anyway thanks...
Rate this:
Please Sign up or sign in to vote.

Solution 2

You must place your code within try{} and show desired message withing catch{}.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100