Click here to Skip to main content
14,452,838 members
   

C#

 
GeneralRe: OleDb Error Pin
OriginalGriff15-Jan-20 10:41
communityengineerOriginalGriff15-Jan-20 10:41 
GeneralRe: OleDb Error Pin
Kevin Marois15-Jan-20 11:57
professionalKevin Marois15-Jan-20 11:57 
GeneralRe: OleDb Error [UPDATED] Pin
Dave Kreskowiak15-Jan-20 10:45
mveDave Kreskowiak15-Jan-20 10:45 
GeneralRe: OleDb Error [UPDATED] Pin
Kevin Marois15-Jan-20 11:51
professionalKevin Marois15-Jan-20 11:51 
GeneralRe: OleDb Error [UPDATED] Pin
Eddy Vluggen15-Jan-20 13:15
professionalEddy Vluggen15-Jan-20 13:15 
GeneralRe: OleDb Error [UPDATED] Pin
Dave Kreskowiak15-Jan-20 13:50
mveDave Kreskowiak15-Jan-20 13:50 
GeneralRe: OleDb Error [UPDATED] Pin
Eddy Vluggen15-Jan-20 13:57
professionalEddy Vluggen15-Jan-20 13:57 
QuestionException Handling Question Pin
Kevin Marois14-Jan-20 19:53
professionalKevin Marois14-Jan-20 19: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 22:19
communityengineerOriginalGriff14-Jan-20 22:19 
AnswerRe: Exception Handling Question Pin
F-ES Sitecore14-Jan-20 23:49
mveF-ES Sitecore14-Jan-20 23:49 
SuggestionRe: Exception Handling Question Pin
Richard Deeming15-Jan-20 1:38
communityengineerRichard Deeming15-Jan-20 1:38 
AnswerRe: Exception Handling Question Pin
Gerry Schmitz15-Jan-20 14:44
mveGerry Schmitz15-Jan-20 14:44 
QuestionHow to add text to a script tag at src using jQuery Pin
Member 1316600712-Jan-20 8:52
MemberMember 1316600712-Jan-20 8:52 
AnswerRe: How to add text to a script tag at src using jQuery Pin
OriginalGriff12-Jan-20 11:25
communityengineerOriginalGriff12-Jan-20 11:25 
Questioni need a c# project using interfaces about anything Pin
Ali Al Akbar Hachem12-Jan-20 5:23
MemberAli Al Akbar Hachem12-Jan-20 5:23 
AnswerRe: i need a c# project using interfaces about anything Pin
OriginalGriff12-Jan-20 5:25
communityengineerOriginalGriff12-Jan-20 5:25 
AnswerRe: i need a c# project using interfaces about anything Pin
Luc Pattyn13-Jan-20 2:03
sitebuilderLuc Pattyn13-Jan-20 2:03 
QuestionAccess winforms application when user right click on a file Pin
Hero201812-Jan-20 2:54
MemberHero201812-Jan-20 2:54 
AnswerRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 3:20
communityengineerOriginalGriff12-Jan-20 3:20 
GeneralRe: Access winforms application when user right click on a file Pin
Hero201812-Jan-20 10:48
MemberHero201812-Jan-20 10:48 
GeneralRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 11:23
communityengineerOriginalGriff12-Jan-20 11:23 
GeneralRe: Access winforms application when user right click on a file Pin
Hero201812-Jan-20 13:22
MemberHero201812-Jan-20 13:22 
GeneralRe: Access winforms application when user right click on a file Pin
OriginalGriff12-Jan-20 23:07
communityengineerOriginalGriff12-Jan-20 23:07 
QuestionHtmlAgilityPack - How to get the Value from the tag <div> into aspx.cs Pin
Member 1316600710-Jan-20 7:02
MemberMember 1316600710-Jan-20 7:02 
AnswerRe: HtmlAgilityPack - How to get the Value from the tag <div> into aspx.cs Pin
Richard Deeming10-Jan-20 7:10
communityengineerRichard Deeming10-Jan-20 7: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.