Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Working with Units and Amounts

, 17 Jul 2013 CPOL
The ultimate Unit and Amount classes for your business and physics applications!
using System;
using System.Runtime.Serialization;

namespace TypedUnits
{
	/// <summary>
	/// Exception thrown when a unit conversion failed, i.e. because you are converting
	/// amounts from one unit into another non-compatible unit.
	/// </summary>
	[Serializable]
	public class UnitConversionException : InvalidOperationException
	{
		public UnitConversionException() : base() { }

		public UnitConversionException(string message) : base(message) { }

		public UnitConversionException(Unit fromUnit, Unit toUnit) : this(String.Format("Failed to convert from unit '{0}' to unit '{1}'. Units are not compatible and no conversions are defined.", fromUnit.Name, toUnit.Name)) { }

		protected UnitConversionException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{ }
	}

	/// <summary>
	/// Exception thrown whenever an exception is referenced by name, but no
	/// unit with the given name is known (registered to the UnitManager).
	/// </summary>
	[Serializable]
	public class UnknownUnitException : ApplicationException
	{

		public UnknownUnitException() : base() { }

		public UnknownUnitException(string message) : base(message) { }

		protected UnknownUnitException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{ }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rudi Breedenraedt
Architect Wolters Kluwer Belgium
Belgium Belgium
Rudi is a Software Architect at Wolters Kluwer Belgium.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411022.1 | Last Updated 17 Jul 2013
Article Copyright 2013 by Rudi Breedenraedt
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid