Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:17:04+00:00 2026-05-22T22:17:04+00:00

button has a Command binding into ViewModel (it runs some Save method in ViewModel).

  • 0

button has a Command binding into ViewModel (it runs some Save method in ViewModel). Method Save can fail and throw an exception.

What is a best practice how to catch those exceptions? It would suffice to show a MessageBox but I do not want to do it in ViewModel (this is not the right way).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:17:05+00:00Added an answer on May 22, 2026 at 10:17 pm

    1 – I don’t believe it’s “not the right way”.

    Having an Exception raised in ViewModel is typically part of the ViewModel logic. Therefore, showing a MessageBox there wouldn’t be “the bad way”.
    Keep in mind that the actual aim of MVVM is NOT to eliminate ALL code-behind, but is actually to clearly separate UI-logic and business-logic. An exception will happen when dealing with business objects — you can handle it in the ViewModel

    2 – Anyway if you want to stick with this approach (I’d qualify it as an extremist MVVM – heh -) you could:

    • Use a validator (have you heard about Binding.ValidationRules ? if not, this article should be useful for you ) to ensure data entered won’t create an Exception
    • Define a specific return value if an Exception happens, ie. try-catch, and if you ever happen to enter in catch, you’ll return a specific Error value which will be treated by UI as an error (you could for example use a Trigger to color the field in red if this specific error value has been returned)

    Anyway again I think that there are a lot of people who want to apply an “extremist MVVM” by eliminating all possible code-behind and introducing complex patterns (Attached Behaviors for example…) just to follow a requirement which is actually nonsense in my opinion. I won’t say I’m absolutely right, but I prefer to see MVVM as a pattern which will simplify my way of coding than a pattern which will introduce me so much pain for basic things (for example I’ve seen people implementing AttachedBehaviors for a simple DoubleClick action. I personally add an EventHandler firing the DoubleClick command to my MVVM when the DoubleClick event is fired. 1 line of code against a 100-lines class + XAML code for the other approach, choose your side. I believe that a simple problem should have a simple solution)

    Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In c#, how can I check to see if a link button has been
i have a button which has a Command property . However , i want
<RichTextBox x:Name=OrigText Margin=0,0,8,0 d:LayoutOverrides=Width/> <Button x:Name=OrigFileBrowse Command={Binding BrowseCommand} CommandParameter={Binding ElementName=OrigText, Path=Document} HorizontalAlignment=Center Margin=0,0,8,2.442 Width=75
I have a button on a toolbar that has its command set to MyControl.Print
I need to create a button that has the same style as ButtonSpec with
My goal is to make a Button that has two Content values. Imagine a
I have a form in C# that has a button that, when clicked, I
I have an ASP.NET page which has a button it it. The button click
What I am trying to achieve is a form that has a button on
I wrote a component that displays a filename, a thumbnail and has a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.