It seems that Microsoft Guidelines for creating custom exceptions state that there should be at least 3 public constructors: empty constructor, the one that takes a message and the one that takes a message and inner exception. My question is why do we need public constructors at all? If I m designing a framework that throws some custom exceptions (e.g. SomethingNotFoundException, etc.), then I would expect the framework users to catch my exceptions and handle them, but not throw them, since the APIs in the framework itself would throw them. So why not just have constructors as internal and only expose public properties that users need to handle these exceptions?
Why have public constructors in custom exceptions
357 Views Asked by Yevgeniy P At
1
There are 1 best solutions below
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in EXCEPTION
- What should i use Exceptions or Monads for handle if service occur a problem?
- Python Requests: Handling Exceptions and Ensuring Server Response
- What is a better way to allow no user input while also preventing non-number inputs
- New error on random number assigned to local variable , Rails
- spring error exception with oauth2 and securityconfig
- Exception thrown: 'System.InvalidOperationException' in Microsoft.Data.SqlClient.dll
- How to fix this Row nested in Column exception issue in Flutter?
- GDI - Why the printing StartPage() function works in 32 bit but raises an exception in 64 bit?
- Handling Invalid Credential or Login error Exception in Python for Network Devices
- Execution failed for task ':app:compileFlutterBuildDebug'. > Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1Error:
- .NET 6 Custom Nuget package referencing other packages - Do I have to include the other packages myself?
- How to prevent Unity from catching and ignoring ALL exceptions
- My Google Apps Script renames all files in a folder from data in a spreadsheet. Can someone explain why it returns an exception error?
- Python (pylint): Catching general exceptions in validation procedures
- Need a simple example how to catch a data type error en C++
Related Questions in FRAMEWORKS
- Symfony Framework - Route cannot be found even if it is defined in Controller
- How to use a custom js framework to build Vite App?
- I'm having issues in setting up my laravel project
- How to pass the result of a computed property to another component in Vue
- Own Pattern / framework for interfacing with components in C
- SwiftUI App only install framework(SwiftUI) not it's dependency(SDK.framework)
- Cannot find protocol declaration for 'TransactionHandlerDelegate'" (Swift/MAUI Interop)
- MicroiFramework Slim / ORM Doctrine - Some classes are missing in the vendor folder,
- When calling another method of controller where injected custom request class. it is showing error Call to a member function validated() on null
- While installing ruby in windows i am getting this error ERROR: Failed to build gem native extension and yaml.h not found
- Strapi 4 + Nuxt 3 Auth Problems
- cant start bundle on apache felix
- Java OSGi implementation for the project
- A framework, error show: Undefined symbols and Linker command failed with exit code 1 (use -v to see invocation)
- Is it allowed in iOS - Swift Dynamic Framework - Contains Multiple Static Library
Related Questions in DESIGN-GUIDELINES
- iOS header design guidelines
- When is it acceptable to declare an instance attribute outside "__init__()"?
- Combined Buy/Restore button for non-consumable IAP in iOS?
- Statuscode guidelines when acting as a middle-man
- What is the good way of storing software version for python CLI ? (<app> --version)
- Layout: center image inside center panel. Using percent units
- Better style inside a vue.js app or outsource to the site embedding it?
- Why have public constructors in custom exceptions
- Integrating Google pay buttons and Apple pay buttons into react-native application
- Are Result objects the cleaner way to handle failure, than exceptions?
- How to distinguish unexpected (boneheaded) exceptions from expected (exogenous) ones?
- Can I package entire iOS app as a Framework?
- Container view for a screen with multiple tableviews in iOS?
- What layout is better for a UI with two card cells per row?
- What is the standard practice for designing REST API if it is being used for inserting / updating a list of records
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Public constructor of user defined exception is required to for unit tests of client code which calls your method and have to handle exception might be thrown. But if a constructor requires argument of custom type either it still could be difficult properly instantiate.
At the same time Microsoft guideline for user defined exceptions contradicts YAGNI and KISS principles and suggests to write and leave unused code. If you have no plan to serialize your exception why to make it serializable? Additional code requires additional tests and so on which increases support cost or/and reduces reliability.