I want to create a bunch of errors. each specific to its own class and module. Then i would like to attach the id to an exception so when my msg change the id is still the same. How do i create this list of errors without maintaining a large global enum ?
user34537
5 Answers
Divide the unsigned 32-bit hexadecimal number range up as a hierarchy:
where:
Then you can have 0 to 0xFF (256) modules, and 0 to 0xFFF (4096) each of classes and errors, and you only have to ensure that each error is unique to its class, and each class is unique to its module, so you don't have to keep all error messages in a single giant table.
Example:
That's module 04, class 01D, error 00A.
Daniel EarwickerDaniel Earwicker
95.9k3131 gold badges182182 silver badges261261 bronze badges
Pavel MinaevPavel Minaev
86.7k2323 gold badges197197 silver badges268268 bronze badges
What's the purpose of having a unique identifier for each error? Any exception that your code throws already has information that uniquely identifies it, i.e. the type of exception and the module name and line of code that threw it. You don't need to assign an ID to an exception to know that it's not the same exception as one with a different type, or module, or line.
Generally speaking, the need to assign a unique ID to an entity emanates from the need to keep other information about that entity in some kind of durable store. What are the characteristics of that durable store? Those requirements almost certainly are going to provide the basis for evaluating the fitness of any particular ID scheme you come up with. What are they?
Robert RossneyRobert Rossney
74.4k2323 gold badges124124 silver badges204204 bronze badges
codymanixcodymanix
18k1414 gold badges7575 silver badges133133 bronze badges
It's a naive idea that every possible 'error' can be assigned a point in 'error space'. Consider a simple example, where a method throws a particular error (I'll be courteous and say 'throws', though in context, it used to be 'returns'):
Perhaps this method is only called from one place in Release 1. That means it's possible in that release to document that error code MyMethodError1 means a particular thing.
In the next release, the method is found to be useful, so it's called from three places. In fact, it's called from two different code paths in one of the places. Does MyMethodError1 mean the same thing now as it used to? I say that it doesn't.
Only by taking into account the circumstances of the calls, as determined by the call stack, can you determine the meaning of the particular exception. An error code does not help with that.
This game will start on Tatooine and will move towards Death Star. From Death Star it goes to the Hoth and then comes to an end in Cloud City. Angry birds star wars 2 download game free. All the birds are equipped with the new powers except for the blue bird. In this game you will play the levels on the earth terrain as well as in space. You can also download.has got the features of Angry Birds and Angry Birds Space.
John SaundersJohn Saunders
149k2222 gold badges207207 silver badges369369 bronze badges
(Redirected from Globally unique identifier)
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The term globally unique identifier (GUID) is also used, typically in software created by Microsoft.
When generated according to the standard methods, UUIDs are for practical purposes unique, without depending for their uniqueness on a central registration authority or coordination between the parties generating them, unlike most other numbering schemes. While the probability that a UUID will be duplicated is not zero, it is close enough to zero to be negligible.
Thus, anyone can create a UUID and use it to identify something with near certainty that the identifier does not duplicate one that has already been, or will be, created to identify something else. Information labeled with UUIDs by independent parties can therefore be later combined into a single database or transmitted on the same channel, with a negligible probability of duplication.
Adoption of UUIDs and GUIDs is widespread, with many computing platforms providing support for generating them and for parsing their textual representation.
History[edit]
UUIDs were originally used in the ApolloNetwork Computing System (NCS) and later in the Open Software Foundation's (OSF) Distributed Computing Environment (DCE). The initial design of DCE UUIDs was based on the NCS UUIDs,[1] whose design was in turn inspired by the (64-bit) unique identifiers defined and used pervasively in Domain/OS, an operating system also designed by Apollo Computer. Later, the Microsoft Windows platforms adopted the DCE design as globally unique identifiers (GUIDs). RFC 4122 registered a URN namespace for UUIDs[2] and recapitulated the earlier specifications, with the same technical content. By the time RFC 4122 was published as a proposed IETF standard, the ITU had also standardized UUIDs, based on the previous standards and early versions of RFC 4122.
Standards[edit]
UUIDs are standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE).[3][4]
UUIDs are documented as part of ISO/IEC 11578:1996 'Information technology â Open Systems Interconnection â Remote Procedure Call (RPC)' and more recently in ITU-T Rec. X.667 | ISO/IEC 9834-8:2005.[5]
The Internet Engineering Task Force (IETF) published the Standards-Track RFC 4122,[2] technically equivalent to ITU-T Rec. X.667 | ISO/IEC 9834-8.
Format[edit]
In its canonical textual representation, the 16 octets of a UUID are represented as 32 hexadecimal (base-16) digits, displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and 4 hyphens). For example:
The 4 bits of digit
M indicate the UUID version, and the 1â3 most significant bits of digit N indicate the UUID variant. In the example, M is 1 , and N is a (10xx2), meaning that the UUID is a variant-1, version-1 UUID; that is, a time-based DCE/RFC 4122 UUID.
The canonical 8-4-4-4-12 format string is based on the 'record layout' for the 16 bytes of the UUID:[2]
These fields correspond to those in versions 1 and 2 of time-based UUIDs, but the same 8-4-4-4-12 representation is used for all UUIDs, even for UUIDs constructed differently.
RFC 4122 section 3 requires that the characters be generated in lower case, while being case-insensitive on input, though some[which?] commonly used implementations violate this rule.
Microsoft GUIDs are sometimes represented with surrounding braces:
This format should not be confused with 'Windows Registry format', which refers to the format within the curly braces.[6]
RFC 4122 defines a Uniform Resource Name (URN) namespace for UUIDs. A UUID presented as a URN appears as follows:[2]
Encoding[edit]
The binary encoding of UUIDs varies between systems. Many systems encode the UUID entirely in a big-endian format.
For example,
00112233-4455-6677-8899-aabbccddeeff is encoded as the bytes 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff .
Other systems, notably Microsoft's marshalling of UUIDs in their COM/OLE libraries, use a mixed-endian format, whereby the first three components of the UUID are little-endian, and the last two are big-endian.
For example,
00112233-4455-6677-8899-aabbccddeeff is encoded as the bytes 33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff .
Variants[edit]
One of the variants defined by RFC 4122, variant 0 (indicated by the one-bit pattern 0xxx2, N =
0.7 ), is for backwards compatibility with the now-obsolete Apollo Network Computing System 1.5 UUID format developed around 1988. In this format, the first 6 octets of the UUID are a 48-bit timestamp (the number of 4-microsecond units of time since 1 Jan 1980 UTC); the next 2 octets are reserved; the next octet is the 'address family'; and the final 7 octets are a 56-bit host ID in the form specified by the address family. Though different in detail, the similarity with modern version-1 UUIDs is evident. The variant bits in the current UUID specification coincide with the high bits of the address family octet in NCS UUIDs. Though the address family could hold values in the range 0.255, only the values 0.13 were ever defined. Accordingly, the variant-0 bit pattern 0xxx avoids conflicts with historical NCS UUIDs, should any still exist in databases.[7]
The 3-bit variant bit pattern 111x2 (N =
e.f ) is reserved for possible future variants.[2]
The other two variants, variants 1 and 2, are used by the current UUID specifications. Variant-1 UUIDs (10xx2N =
8.b , 2 bits) are referred to as RFC 4122/DCE 1.1 UUIDs, or 'LeachâSalz' UUIDs, after the authors of the original Internet Draft. Variant 2 (110x2N = c.d , 3 bits) is characterized in the RFC as 'reserved, Microsoft Corporation backward compatibility' and was used for early GUIDs on the Microsoft Windows platform. Variant bits aside, the two variants are the same, except that when reduced to a binary form for storage or transmission, variant-1 UUIDs use 'network' (big-endian) byte order, while variant-2 GUIDs use 'native' (little-endian) byte order. In their textual representations, variants 1 and 2 are the same, except for the variant bits.
When byte swapping is required to convert between the big-endian byte order of variant 1 and the little-endian byte order of variant 2, the fields above define the swapping. The first three fields are unsigned 32- and 16-bit integers and are subject to swapping, while the last two fields consist of uninterpreted bytes, not subject to swapping. This byte swapping applies even for versions 3, 4, and 5, where the canonical fields do not correspond to the content of the UUID.[2]
Note that while some important GUIDs, such as the identifier for the Component Object ModelIUnknown interface, are nominally variant-2 UUIDs, many identifiers generated and used in Microsoft Windows software and referred to as 'GUIDs' are standard variant-1 RFC 4122/DCE 1.1 network-byte-order UUIDs, rather than little-endian variant-2 UUIDs. The current version of the Microsoft
guidgen tool produces standard variant-1 UUIDs. Some Microsoft documentation states that 'GUID' is a synonym for 'UUID',[8] as standardized in RFC 4122. RFC 4122 itself states that UUIDs 'are also known as GUIDs'. All this suggests that 'GUID', while originally referring to a variant of UUID used by Microsoft, has become simply an alternative name for UUID, with both variant-1 and variant-2 GUIDs being extant.
Versions[edit]
For both variants 1 and 2, five 'versions' are defined in the standards, and each version may be more appropriate than the others in specific use cases. Version is indicated by the
M in the string representation.
Version-1 UUIDs are generated from a time and a node id (usually the MAC address); version-2 UUIDs are generated from an identifier (usually a group or user id), time, and a node id; versions 3 and 5 produce deterministic UUIDs generated by hashing a namespace identifier and name; and version-4 UUIDs are generated using a random or pseudo-random number.
Nil UUID[edit]
The 'nil' UUID, a special case, is the UUID
00000000-0000-0000-0000-000000000000 ; that is, all bits set to zero.[2]Version 1 (date-time and MAC address)[edit]
Version 1 concatenates the 48-bit MAC address of the 'node' (that is, the computer generating the UUID), with a 60-bit timestamp, being the number of 100-nanosecond intervals since midnight 15 October 1582 Coordinated Universal Time (UTC), the date on which the Gregorian calendar was first adopted. RFC 4122 states that the time value rolls over around 3400 AD,[2] depending on the algorithm used, which implies that the 60-bit timestamp is a signed quantity. However some software, such as the libuuid library, treats the timestamp as unsigned, putting the rollover time in 5236 AD.[9]
A 13- or 14-bit 'uniquifying' clock sequence extends the timestamp in order to handle cases where the processor clock does not advance fast enough, or where there are multiple processors and UUID generators per node. When UUIDs are generated faster than the system clock could advance, the lower bits of the timestamp fields can be generated by incrementing it every time a UUID is being generated, to simulate a high resolution timestamp. With each version 1 UUID corresponding to a single point in space (the node) and time (intervals and clock sequence), the chance of two properly generated version-1 UUIDs being unintentionally the same is practically nil. Since the time and clock sequence total 74 bits, 274 (1.8Ã1022, or 18 sextillion) version-1 UUIDs can be generated per node id, at a maximal average rate of 163 billion per second per node id.[2]
In contrast to other UUID versions, version-1 and -2 UUIDs based on MAC addresses from network cards rely for their uniqueness in part on an identifier issued by a central registration authority, namely the Organizationally Unique Identifier (OUI) part of the MAC address, which is issued by the IEEE to manufacturers of networking equipment.[10] The uniqueness of version-1 and version-2 UUIDs based on network-card MAC addresses also depends on network-card manufacturers properly assigning unique MAC addresses to their cards, which like other manufacturing processes is subject to error.
Usage of the node's network card MAC address for the node id means that a version-1 UUID can be tracked back to the computer that created it. Documents can sometimes be traced to the computers where they were created or edited through UUIDs embedded into them by word processing software. This privacy hole was used when locating the creator of the Melissa virus.[11]
RFC 4122 does allow the MAC address in a version-1 (or 2) UUID to be replaced by a random 48-bit node id, either because the node does not have a MAC address, or because it is not desirable to expose it. In that case, the RFC requires that the least significant bit of the first octet of the node id should be set to 1.[2] This corresponds to the multicast bit in MAC addresses, and setting it serves to differentiate UUIDs where the node id is randomly generated from those based on MAC addresses from network cards, which typically have unicast MAC addresses.[2]
Version 2 (date-time and MAC address, DCE security version)[edit]
RFC 4122 reserves version 2 for 'DCE security' UUIDs; but it does not provide any details. For this reason, many UUID implementations omit version 2. However, the specification of version-2 UUIDs is provided by the DCE 1.1 Authentication and Security Services specification.[4]
Version-2 UUIDs are similar to version 1, except that the least significant 8 bits of the clock sequence are replaced by a 'local domain' number, and the least significant 32 bits of the timestamp are replaced by an integer identifier meaningful within the specified local domain. On POSIX systems, local-domain numbers 0 and 1 are for user ids (UIDs) and group ids (GIDs) respectively, and other local-domain numbers are site-defined.[4] On non-POSIX systems, all local domain numbers are site-defined.
The ability to include a 40-bit domain/identifier in the UUID comes with a tradeoff. On the one hand, 40 bits allow about 1 trillion domain/identifier values per node id. On the other hand, with the clock value truncated to the 28 most significant bits, compared to 60 bits in version 1, the clock in a version 2 UUID will 'tick' only once every 429.49 seconds, a little more than 7 minutes, as opposed to every 100 nanoseconds for version 1. And with a clock sequence of only 6 bits, compared to 14 bits in version 1, only 64 unique UUIDs per node/domain/identifier can be generated per 7-minute clock tick, compared to 16,384 clock sequence values for version 1.[12] Thus, Version 2 may not be suitable for cases where UUIDs are required, per node/domain/identifier, at a rate exceeding about 1 per 7 seconds.
Versions 3 and 5 (namespace name-based)[edit]
Version-3 and version-5 UUIDs are generated by hashing a namespace identifier and name. Version 3 uses MD5 as the hashing algorithm, and version 5 uses SHA-1.[2]
The namespace identifier is itself a UUID. The specification provides UUIDs to represent the namespaces for URLs, fully qualified domain names, object identifiers, and X.500distinguished names; but any desired UUID may be used as a namespace designator.
To determine the version-3 UUID corresponding to a given namespace and name, the UUID of the namespace is transformed to a string of bytes, concatenated with the input name, then hashed with MD5, yielding 128 bits. Then 6 or 7 bits are replaced by fixed values, the 4-bit version (e.g. 00112 for version 3), and the 2- or 3-bit UUID 'variant' (e.g. 102 indicating a RFC 4122 UUIDs, or 1102 indicating a legacy Microsoft GUID). Since 6 or 7 bits are thus predetermined, only 121 or 122 bits contribute to the uniqueness of the UUID.
Version-5 UUIDs are similar, but SHA-1 is used instead of MD5. Since SHA-1 generates 160-bit digests, the digest is truncated to 128 bits before the version and variant bits are replaced.
Version-3 and version-5 UUIDs have the property that the same namespace and name will map to the same UUID. However, neither the namespace nor name can be determined from the UUID, given the other, except by brute-force search.
RFC 4122 recommends version 5 (SHA-1) over version 3 (MD5) and counsels against use of UUIDs of either version as security credentials.[2]
Version 4 (random)[edit]
A version 4 UUID is randomly generated. As in other UUIDs, 4 bits are used to indicate version 4, and 2 or 3 bits to indicate the variant (102 or 1102 for variants 1 and 2 respectively). Thus, for variant 1 (that is, most UUIDs) a random version-4 UUID will have 6 predetermined variant and version bits, leaving 122 bits for the randomly generated part, for a total of 2122, or 5.3Ã1036 (5.3 undecillion) possible version-4 variant-1 UUIDs. There are half as many possible version-4 variant-2 UUIDs (legacy GUIDs) because there is one less random bit available, 3 bits being consumed for the variant.
Collisions[edit]
Collision occurs when the same UUID is generated more than once and assigned to different referents. In the case of standard version-1 and version-2 UUIDs using unique MAC addresses from network cards, collisions can occur only when an implementation varies from the standards, either inadvertently or intentionally.
In contrast to version 1 and 2, UUIDs using randomly generated node ids, hash-based version-3 and version-5 UUIDs, and random version-4 UUIDs, collisions can occur even without implementation problems, albeit with a probability so small that it can normally be ignored. This probability can be computed precisely based on analysis of the birthday problem.[13]
For example, the number of random version-4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion, computed as follows:[14]
This number is equivalent to generating 1 billion UUIDs per second for about 85 years, and a file containing this many UUIDs, at 16 bytes per UUID, would be about 45 exabytes, many times larger than the largest databases currently in existence, which are on the order of hundreds of petabytes.[15][16]
The smallest number of version-4 UUIDs which must be generated for the probability of finding a collision to be p is approximated by the formula
Thus, the probability to find a duplicate within 103 trillion version-4 UUIDs is one in a billion.
In practice, collisions are reported.[17][18][19] Such incidents are considered software bugs.
Uses[edit]
Significant uses include ext2/ext3/ext4 filesystem userspace tools (e2fsprogs uses libuuid provided by util-linux), LUKS encrypted partitions, GNOME, KDE, and macOS,[20] most of which are derived from the original implementation by Theodore Ts'o.[9]
One of the uses of UUIDs in Solaris (using Open Software Foundation implementation) is identification of a running operating system instance for the purpose of pairing crash dump data with Fault Management Event in the case of kernel panic.[21]
In COM[edit]
There are several flavors of GUIDs used in Microsoft's Component Object Model (COM):
As database keys[edit]
UUIDs are commonly used as a unique key in database tables. The NEWID function in Microsoft SQL Server version 4 Transact-SQL returns standard random version-4 UUIDs, while the NEWSEQUENTIALID function returns 128-bit identifiers similar to UUIDs which are committed to ascend in sequence until the next system reboot.[25] The Oracle DatabaseSYS_GUID function does not return a standard GUID, despite the name. Instead, it returns a 16-byte 128-bit RAW value based on a host identifier and a process or thread identifier, somewhat similar to a GUID.[26]PostgreSQL contains a UUID datatype[27] and can generate most versions of UUIDs through the use of functions from modules.[28][29]MySQL provides a UUID function, which generates standard version-1 UUIDs.[30]
The random nature of standard UUIDs of versions 3, 4, and 5, and the ordering of the fields within standard versions 1 and 2 may create problems with database locality or performance when UUIDs are used as primary keys. For example, in 2002 Jimmy Nilsson reported a significant improvement in performance with Microsoft SQL Server when the version-4 UUIDs being used as keys were modified to include a non-random suffix based on system time. This so-called 'COMB' (combined time-GUID) approach made the UUIDs non-standard and significantly more likely to be duplicated, as Nilsson acknowledged, but Nilsson only required uniqueness within the application.[31]
See also[edit]
References[edit]
External links[edit]
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Universally_unique_identifier&oldid=902731872'
Lately, I ran into an issue, trying to identify the uniqueness of machines across platforms. Suffice to say, itâs a lot complicated than what I initially thought.
The traditional method of leverage the MAC address as the computerâs unique identifier is not going to work anymore. Why? Because each computer can easily have multiple MAC address from multiple network adapter. For example, almost all laptops come with one Ethernet, one Wi-Fi network adapters and one Bluetooth. The MAC address quickly changes every time when your computer connects from a wired network to a wireless network. Moreover, the MAC address even changes when you are on or off a VPN connection. Not to mention when itâs running on a virtual machine. With that, the days of using MAC address as a unique identifier of a computer is gone.
Now what?
Use UUID as the Identifier When You Can
We covered in the past that you can use the wmic command to find all the system info from your machine. And we can use the same too here.
wmic csproduct get UUID
That UUID is the best way to ID a machine, it exists in Windows, Mac and many other platforms. It is a 32 characters in length, universally unique identifier. You can run the above wmic command to get it.
But wait, thatâs not always the case. Some of the motherboard vendors might not include this UUID in their motherboard, which is quite common on those non-OEM machines. In that case, when you use wmic trying to retrieve it you will get all FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF as the ID back.
The Alternative
In Windows, there are a couple of alternatives that you can use if UUID idea failed.
The first one is to use your Windows product ID. This is the ID you can retrieve easily from Control Panel > System and Security > System
But that doesnât always guarantee the uniqueness of the machine. For example, on those Windows volume activated or none genuine Windows machines, the Product ID will always be the same. Also keep in mind that if you re-install Windows, this ID might change as well.
The second option is to use the hard driveâs serial number as the unique identifier. Thatâs almost the better approach if UUID fails, meaning that you can rely on the HDDâs serial number.
wmic DISKDRIVE get SerialNumber
The above command will do the trick. It even returns all of the numbers if you have multiple hard drives physically connected to your machine.
Conclusion
If you want to ID a machine, the old way of using Mac address is not reliable anymore. There are better ways around. We only listed two options here and if you know any others, feel free to share them in the comment below.
Global Unique Identifier Network Services/Update on July 17, 2015/
There is actually another way to uniquely identify each Windows PC. Open up Registry and navigate to
HKEY_LOCAL_MACHINESOFTWAREMicrosoftCryptography
Find the key called âMachineGuidâ this key is generated uniquely during the installation of Windows and it wonât change regardless of any hardware swap (apart from replacing the boot-able hard drive where the OS are installed on). That means if you want to keep tracking installation per OS this is another alternative. It wonât change unless you do a fresh reinstall of Windows.
/update on Jan 9, 2019/
You can run the following cmdlet in PowerShell console to get the UUID as well.
Related Posts
[â¦] Windows 머ì ì ê³ ì íê² ìë³íë ìµì ì ë°©ë² [â¦]
Lately, I ran into an issue, trying to identify the uniqueness of machines across platforms. Suffice to say, itâs a lot complicated than what I initially thought.
The traditional method of leverage the MAC address as the computerâs unique identifier is not going to work anymore. Why? Because each computer can easily have multiple MAC address from multiple network adapter. For example, almost all laptops come with one Ethernet, one Wi-Fi network adapters and one Bluetooth. The MAC address quickly changes every time when your computer connects from a wired network to a wireless network. Moreover, the MAC address even changes when you are on or off a VPN connection. Not to mention when itâs running on a virtual machine. With that, the days of using MAC address as a unique identifier of a computer is gone.
Now what?
Use UUID as the Identifier When You Can
We covered in the past that you can use the wmic command to find all the system info from your machine. And we can use the same too here.
wmic csproduct get UUID
That UUID is the best way to ID a machine, it exists in Windows, Mac and many other platforms. It is a 32 characters in length, universally unique identifier. You can run the above wmic command to get it.
But wait, thatâs not always the case. Some of the motherboard vendors might not include this UUID in their motherboard, which is quite common on those non-OEM machines. In that case, when you use wmic trying to retrieve it you will get all FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF as the ID back.
The Alternative
In Windows, there are a couple of alternatives that you can use if UUID idea failed.
The first one is to use your Windows product ID. This is the ID you can retrieve easily from Control Panel > System and Security > System
But that doesnât always guarantee the uniqueness of the machine. For example, on those Windows volume activated or none genuine Windows machines, the Product ID will always be the same. Also keep in mind that if you re-install Windows, this ID might change as well.
The second option is to use the hard driveâs serial number as the unique identifier. Thatâs almost the better approach if UUID fails, meaning that you can rely on the HDDâs serial number.
wmic DISKDRIVE get SerialNumber
The above command will do the trick. It even returns all of the numbers if you have multiple hard drives physically connected to your machine.
Conclusion
If you want to ID a machine, the old way of using Mac address is not reliable anymore. There are better ways around. We only listed two options here and if you know any others, feel free to share them in the comment below.
/Update on July 17, 2015/
There is actually another way to uniquely identify each Windows PC. Open up Registry and navigate to
HKEY_LOCAL_MACHINESOFTWAREMicrosoftCryptography
Find the key called âMachineGuidâ this key is generated uniquely during the installation of Windows and it wonât change regardless of any hardware swap (apart from replacing the boot-able hard drive where the OS are installed on). That means if you want to keep tracking installation per OS this is another alternative. It wonât change unless you do a fresh reinstall of Windows.
Global Unique Identifier Network Number/update on Jan 9, 2019/
You can run the following cmdlet in PowerShell console to get the UUID as well.
Related Posts
[â¦] Windows 머ì ì ê³ ì íê² ìë³íë ìµì ì ë°©ë² [â¦]
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |