How to avoid crash multi projects application

zleug 51 Reputation points
2020-10-30T19:49:22.7+00:00

Hi All.
I have multi projects WPF application. I understand how to prevent the crash if error become in UI layer. But how to create message and inform a user if error happens in data layer? How to send a message on a screen if try-catch block catch an error on data layer? I will appreciate if someone can show sample how to do it.

Thanks

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. DaisyTian-1203 11,626 Reputation points
    2020-11-02T03:37:48.453+00:00

    You can use MessageBox.Show Method in the catch to show the error messge in the data layer.

    1. Add System.Windows.Forms in your layer reference
    2. Add Using System.Windows.Forms; for the class which you want to use.
    3. Put MessageBox.Show("This is Error Meaage"); in the catch to show the message.

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Duane Arnold 3,211 Reputation points
    2020-11-02T09:02:06.717+00:00

    Here is a Windows form Core solution that is a 3 layers solution that is using GEH implemented in the Program.cs

    https://www.codeproject.com/Articles/43182/Centralised-Exception-Handling-in-C-Windows-Applic

    A try/catch is nowhere to be found in any of the layers. However, validation messages are being sent back from the BLL objects back to the presentation layer. No messages are sent from the DAL not unless I am throwing an exception in the DAL that is will be caught by the GEH established in the presentation layer.

    https://github.com/darnold924/PubComanyWinCore

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.