Click here to Skip to main content
16,020,565 members
Home / Discussions / C#
   

C#

 
Questionis this one possible ? Pin
jtmtv1828-Feb-03 2:07
jtmtv1828-Feb-03 2:07 
AnswerRe: is this one possible ? Pin
leppie1-Mar-03 0:00
leppie1-Mar-03 0:00 
GeneralRe: is this one possible ? Pin
jtmtv181-Mar-03 10:58
jtmtv181-Mar-03 10:58 
GeneralRe: is this one possible ? Pin
leppie1-Mar-03 11:23
leppie1-Mar-03 11:23 
GeneralRe: is this one possible ? Pin
jtmtv181-Mar-03 11:46
jtmtv181-Mar-03 11:46 
GeneralRe: is this one possible ? Pin
leppie1-Mar-03 21:36
leppie1-Mar-03 21:36 
GeneralRe: is this one possible ? Pin
jtmtv181-Mar-03 22:50
jtmtv181-Mar-03 22:50 
GeneralRe: is this one possible ? Pin
leppie1-Mar-03 23:16
leppie1-Mar-03 23:16 
OI what happened to rest of the message Poke tongue | ;-P

Like said thsoe 2 functions are static and internal to my exception class. Now if you design it nicely, you can have something like this:

public class MyException {
internal enum ErrorCode 
{
  None,
  User,
  Programmer,
  Unknown,
}

static ErrorCode errorcode = ErrorCode.None;

internal static ErrorCode Error
{
  get {
    return errorcode;
  }
  set {errorcode = value;}
}

internal static string GetErrorDescription(ErrorCode code)
{
  switch(code)
  {
  case ErrorCode.User:
    return "User error occured, check blah blah for dohdoh";
  case ErrorCode.Programmer:
    return "Programmer error occured, email blah";
  case ErrorCode.Unknown:
    return "Unknown error occured, no help available";
  case default:
    return "No error";
  }
}

public MyException():this(Error){}
internal MyException(ErrorCode code):base(GetErrorDescription(code))
{
  errorcode = ErrorCode.None; //reset the errorcode, base gets called 1st.
}
}
In you calling code:
...
if (somestring == "badstring") 
{
  MyException.Error = Error.User;
  throw new MyException();
}
...
Hope this helps Smile | :)

PS: maybe another helper function:
static void CheckString(string str)
{
  if (somestring == "badstring") 
  {
    MyException.Error = Error.User;
    throw new MyException();
  }  
}
...
CheckString("badstring");
...


I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
GeneralRe: is this one possible ? Pin
jtmtv181-Mar-03 23:26
jtmtv181-Mar-03 23:26 
GeneralRe: is this one possible ? Pin
leppie1-Mar-03 23:30
leppie1-Mar-03 23:30 
GeneralRe: is this one possible ? Pin
jtmtv181-Mar-03 23:42
jtmtv181-Mar-03 23:42 
GeneralRe: is this one possible ? Pin
leppie2-Mar-03 2:43
leppie2-Mar-03 2:43 
GeneralRe: is this one possible ? Pin
jtmtv182-Mar-03 11:56
jtmtv182-Mar-03 11:56 
QuestionHow to get AppInfo/Documentation from an XML Schema via XmlDocument (DOM) in C#? Pin
Mirco J. Nimmrichter27-Feb-03 23:12
Mirco J. Nimmrichter27-Feb-03 23:12 
GeneralFind Printer List available... Pin
bania27-Feb-03 20:16
bania27-Feb-03 20:16 
GeneralRe: Find Printer List available... Pin
Stephane Rodriguez.28-Feb-03 20:39
Stephane Rodriguez.28-Feb-03 20:39 
GeneralThank You.. Pin
bania2-Mar-03 13:22
bania2-Mar-03 13:22 
GeneralRe: Thank You.. Pin
leppie3-Mar-03 6:28
leppie3-Mar-03 6:28 
GeneralFew Questions Pin
chito27-Feb-03 20:07
chito27-Feb-03 20:07 
GeneralRe: Few Questions Pin
Brian Olej28-Feb-03 9:45
Brian Olej28-Feb-03 9:45 
GeneralRe: Few Questions Pin
Stephane Rodriguez.28-Feb-03 20:52
Stephane Rodriguez.28-Feb-03 20:52 
Generallame encoding Pin
grv57527-Feb-03 18:25
grv57527-Feb-03 18:25 
GeneralClass Library Question .. Pin
Dato27-Feb-03 14:55
Dato27-Feb-03 14:55 
GeneralRe: Class Library Question .. Pin
David Stone27-Feb-03 15:01
sitebuilderDavid Stone27-Feb-03 15:01 
GeneralRe: Class Library Question .. Pin
leppie27-Feb-03 20:54
leppie27-Feb-03 20:54 

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.