'how to make a function inside a catch block?
Im a beginner in coding so please bare with my lack of knowledge, thank you.
i have a code initially looking like this in my catch block
catch (Exception ex)
{
String[] msg = ex.Message.Split(new char[] { '|' });
if (msg[0] == "EXIST")
{
lblStatus.CssClass = "Error";
lblStatus.Text = "<span class='" + Resources.Resource.LangParam2 + "'>" + Resources.Resource.UserNameAlreadyExists + "</span>";
return;
}
else
{
throw ex;
}
}
i am trying to make the code in the catch function into a library function as many code will use it. for example I am trying smth like this
catch (Exception ex)
{
String[] msg = ex.Message.Split(new char[] { '|' });
Util.GetErrorMessage("SubUser1");
else
{
throw ex;
}
}
and inside my Util.cs code is as below
public static void GetErrorMessage(string acc)
{
if(acc == "SubUser1")
{
String[] msg = new string[] { };
if (msg[0] == "EXIST")
{
string Class = "Error";
string Text = "<span class='" + Resources.Resource.LangParam2 + "'>" + Resources.Resource.UserNameAlreadyExists + "</span>";
return;
}
}
}
any idea that i can make this happen? thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
