❔ (MVC web app) How can I handle exceptions/errors in this case?
So I was thinking of placing all this code (the one inside the function) inside a try catch block, and in the catch statement, if there's an exception catch it and then display an error message such as "Something went wrong, error #0001", is it bad practice? what could i do instead?
18 Replies
Ooof ouch owie that
.Result
Use proper async code pls
For exceptions, you'd usually rely on the exception handling middlewareIn the provided AddTransaction method, it seems there's a need for improvements related to asynchronous operations, exception handling, and code structure. Here's an enhanced version with comments to illustrate some changes:
sorry
thank you for your answer, so it is okay to use a try catch block for all the code?
💯 . I have over 7 year experience and that's the best way you will ever handle that, but avoid absolute url inside your application https://www.linkedin.com/in/haron-njuguna/
yeah, will fix it, thank you so much!
If you get stuck, You can always reach out in my DM. especially ln
btw i was thinking of redirecting to the same view but changing the red <p> as i showed here if there was an error, do you think it is better than redirecting to an error view? @softmek
You can use alert message for that. Imagine all cards didn’t load, the page will be well written in red haha! 😛
Which FE framework are you using, i can suggest what I use
i'm not proficient in any framework yet so i'm just using html with razor
GitHub
MVC.Budget/MVC.Budget/MVC.Budget.JsPeanut/Views/Categories/Index.cs...
Contribute to JsPeanut/MVC.Budget development by creating an account on GitHub.
You can use https://codeseven.github.io/toastr/demo.html
that is amazing
it should be shown after reloading the page right?
When an error occurs display the alert which will disappear in few seconds
For the dates, you can checkout https://momentjs.com/docs/, Whatever you have done will be greatly affected by timezones
alright, thank you man, i really appreciate your help!
No problem man, am off the grid! it's late 3:15am here, you can hit me up in linkedin haha, 👌🏾
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.