Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: OleDb Error Pin
OriginalGriff15-Jan-20 9:41
mveOriginalGriff15-Jan-20 9:41 
GeneralRe: OleDb Error Pin
Kevin Marois15-Jan-20 10:57
professionalKevin Marois15-Jan-20 10:57 
GeneralRe: OleDb Error [UPDATED] Pin
Dave Kreskowiak15-Jan-20 9:45
mveDave Kreskowiak15-Jan-20 9:45 
GeneralRe: OleDb Error [UPDATED] Pin
Kevin Marois15-Jan-20 10:51
professionalKevin Marois15-Jan-20 10:51 
GeneralRe: OleDb Error [UPDATED] Pin
Eddy Vluggen15-Jan-20 12:15
professionalEddy Vluggen15-Jan-20 12:15 
GeneralRe: OleDb Error [UPDATED] Pin
Dave Kreskowiak15-Jan-20 12:50
mveDave Kreskowiak15-Jan-20 12:50 
GeneralRe: OleDb Error [UPDATED] Pin
Eddy Vluggen15-Jan-20 12:57
professionalEddy Vluggen15-Jan-20 12:57 
QuestionException Handling Question Pin
Kevin Marois14-Jan-20 18:53
professionalKevin Marois14-Jan-20 18:53 
In this example from my DAL, both THROWs would be caught by my Global Exception handler, which logs the error, pops up a "Error Occured" dialog, and shuts down the app.
/// <summary>
/// Deletes a Role.
/// </summary>
/// <param name="id">The Role id.</param>
public void DeleteRole(int id)
{
    try
    {
        var role = (from u in dataContext.Roles
                    where u.Id == id
                    select u).FirstOrDefault();
        var hasUsers = (from u in dataContext.Users
                        where u.RoleId == id
                        select u).Any();
        if (hasUsers)
        {
            //<==== THIS SHOULD BE SEEN BY THE USER
            throw new Exception($"The role '{role.RoleName}' cannot be deleted because it has users assigned to it." );
        }
        else
        {
            if (role != null)
            {
                role.IsDeleted = true;
                dataContext.SubmitChanges();
            }
        }
    }
    catch (Exception)
    {
        //<==== IF HERE, SOMETHING ELSE WENT WRONG, SO LET THE GLOBAL 
        //      EXCEPTION HANDLER HANDLE IT
        throw;  
    }
}
So, how would you allow the user exception to be handled without closing the app? I'd like the message of the exception to appear in a MessageBox.

I could replace those types of exceptions with a custom exception, the catch those before the global handler gets it.

What's the right way to handle this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Exception Handling Question Pin
OriginalGriff14-Jan-20 21:19
mveOriginalGriff14-Jan-20 21:19 
AnswerRe: Exception Handling Question Pin
F-ES Sitecore14-Jan-20 22:49
professionalF-ES Sitecore14-Jan-20 22:49 
SuggestionRe: Exception Handling Question Pin
Richard Deeming15-Jan-20 0:38
mveRichard Deeming15-Jan-20 0:38 
AnswerRe: Exception Handling Question Pin
Gerry Schmitz15-Jan-20 13:44
mveGerry Schmitz15-Jan-20 13:44 
QuestionHow to add text to a script tag at src using jQuery Pin
Member 1316600712-Jan-20 7:52
Member 1316600712-Jan-20 7:52 
AnswerRe: How to add text to a script tag at src using jQuery Pin
OriginalGriff12-Jan-20 10:25
mveOriginalGriff12-Jan-20 10:25 
Questioni need a c# project using interfaces about anything Pin
Ali Al Akbar Hachem12-Jan-20 4:23
Ali Al Akbar Hachem12-Jan-20 4:23 
AnswerRe: i need a c# project using interfaces about anything Pin
OriginalGriff12-Jan-20 4:25
mveOriginalGriff12-Jan-20 4:25 
AnswerRe: i need a c# project using interfaces about anything Pin
Luc Pattyn13-Jan-20 1:03
sitebuilderLuc Pattyn13-Jan-20 1:03 
QuestionAccess winforms application when user right click on a file Pin
Hero201812-Jan-20 1:54
Hero201812-Jan-20 1:54 
AnswerRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 2:20
mveOriginalGriff12-Jan-20 2:20 
GeneralRe: Access winforms application when user right click on a file Pin
Hero201812-Jan-20 9:48
Hero201812-Jan-20 9:48 
GeneralRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 10:23
mveOriginalGriff12-Jan-20 10:23 
GeneralRe: Access winforms application when user right click on a file Pin
Hero201812-Jan-20 12:22
Hero201812-Jan-20 12:22 
GeneralRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 22:07
mveOriginalGriff12-Jan-20 22:07 
QuestionHtmlAgilityPack - How to get the Value from the tag <div> into aspx.cs Pin
Member 1316600710-Jan-20 6:02
Member 1316600710-Jan-20 6:02 
AnswerRe: HtmlAgilityPack - How to get the Value from the tag <div> into aspx.cs Pin
Richard Deeming10-Jan-20 6:10
mveRichard Deeming10-Jan-20 6:10 

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.