Exception
-
How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }
-
How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }
Hi, exception is a way to provide information about an unusual behavior in a method. Sometimes this behavior is caused by an error. What you want is the error code. So the "default" Exception class you are catching does not provide an error code http://msdn.microsoft.com/en-us/library/system.exception.aspx[^] But if the specific class of the exception thrown by the called method contains a code, than you can receive this code by accessing the property from the exception (you have to cast before or catch a more specific type). If you need further help I recommend to post the code also, causing the exception. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hi, exception is a way to provide information about an unusual behavior in a method. Sometimes this behavior is caused by an error. What you want is the error code. So the "default" Exception class you are catching does not provide an error code http://msdn.microsoft.com/en-us/library/system.exception.aspx[^] But if the specific class of the exception thrown by the called method contains a code, than you can receive this code by accessing the property from the exception (you have to cast before or catch a more specific type). If you need further help I recommend to post the code also, causing the exception. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
- for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
-
- for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
- you have to catch the FormatException first. And as second one the common Exception. When not, the FormatException will never be catched, because a FormatException is an Exception. 2) Nowhere, because Exception are classes which can be derived from. So there are thousands of Exception types out there (waiting to be catched :-D ) (For all framework exceptions you can browse through msdn...) 3) Maybe you can explain what you want to achieve? To get an idea for exception handlung start reading this msdn article: http://msdn.microsoft.com/en-us/library/ms173160.aspx[^] Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
- you have to catch the FormatException first. And as second one the common Exception. When not, the FormatException will never be catched, because a FormatException is an Exception. 2) Nowhere, because Exception are classes which can be derived from. So there are thousands of Exception types out there (waiting to be catched :-D ) (For all framework exceptions you can browse through msdn...) 3) Maybe you can explain what you want to achieve? To get an idea for exception handlung start reading this msdn article: http://msdn.microsoft.com/en-us/library/ms173160.aspx[^] Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
Before all Thanks for your attention and Help ! I want to translate Exception to my Language (Persian,Farsi) then show the translate exception.(Note: I dont want to write down the error in catch like bellow: try { } catch { messagebox.show("Not like this"); } OR try { } catch(Exception ex) { messagebox.show("Not like this"); } OR try { } catch(FormatException ex) { messagebox.show("Not like this"); }
-
- for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
Isn't this exactly the same question that you posted three hours ago under the title ERROR? It is generally considered bad form to post the same question multiple times.
-
How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }