protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (txtName.Text == "Jaya" && txtPwd.Text == "1234")
{
Server.Transfer("Retailer.aspx");
}
else
{
Server.Transfer("Login.aspx");
}
}
catch(Exception ex)
{
oExceptionManager.LogError(ex.Message, "Error From btn btnSubmit_Click in Login.aspx.cs");
}
}
in my code the catch block is executing if it is true or false but i want to execute when i got false condtions pls modify my code
Naimish MakwanaPosted Oct 6, 2023, 9:33 AM
In your code, the
tryandcatchblocks are correctly set up to catch exceptions that might occur within thetryblock. However, based on your requirement, it seems like you want to handle exceptions only when there's an error or issue with the code inside thetryblock. If you don't want to catch exceptions for business logic conditions like incorrect login credentials, you should modify your code as follows:In the modified code, I've removed the
catchblock around the entiretryblock. Instead, I added a custom methodShowErrorMessageto handle the case of incorrect login credentials within theelseblock. This way, exceptions will only be caught and logged for unexpected issues, and you can handle business logic issues separately.Thanks
Naimish Makwana