Index: trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 384)
+++ trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 385)
@@ -90,5 +90,5 @@
 	Zero = &h4
 	'! 左揃え、-。フィールド内で左揃えにする。
-	Left = &h8
+	LeftSide = &h8
 	/*! 代替表記、#。
 	<ul>
@@ -867,5 +867,5 @@
 		If .Length < field Then
 			Dim embeddedSize = field - .Length
-			If flags And Left Then
+			If flags And LeftSide Then
 				.Append(&h20, embeddedSize)
 			Else
@@ -898,5 +898,5 @@
 	Dim sb = New System.Text.StringBuilder(
 		x, 0, System.Math.Min(x.Length As DWord, d) As Long, field)
-	AdjustFieldWidth(sb, field, flags And Left)
+	AdjustFieldWidth(sb, field, flags And LeftSide)
 	FormatString = sb.ToString()
 End Function
@@ -915,5 +915,5 @@
 	Dim sb = New System.Text.StringBuilder(field + 1)
 	sb.Append(x)
-	AdjustFieldWidth(sb, field, flags And Left)
+	AdjustFieldWidth(sb, field, flags And LeftSide)
 	FormatCharacter = sb.ToString()
 End Function
@@ -1094,5 +1094,5 @@
 				flags Or= Sign
 			Case &h2d '-
-				flags Or = Left
+				flags Or = LeftSide
 			Case &h26 '&
 				flags Or= BPrefix
@@ -1122,5 +1122,5 @@
 	If ReadInt(fmt, params, paramsCount, t) Then
 		If t < 0 Then
-			flags Or= Left
+			flags Or= LeftSide
 			fieldWidth = -t As DWord
 		Else
Index: trunk/Include/Classes/ActiveBasic/Strings/Strings.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 384)
+++ trunk/Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 385)
@@ -95,5 +95,5 @@
 	ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
 	If ChrCmp = 0 Then
-		ChrCmp = ( size1 - size2 ) As Long
+		ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
 	End If
 End Function
@@ -102,5 +102,5 @@
 	ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
 	If ChrCmp = 0 Then
-		ChrCmp = ( size1 - size2 ) As Long
+		ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
 	End If
 End Function
Index: trunk/Include/Classes/ActiveBasic/misc.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/misc.ab	(revision 385)
+++ trunk/Include/Classes/ActiveBasic/misc.ab	(revision 385)
@@ -0,0 +1,7 @@
+'Classes/ActiveBasic/misc.ab
+
+Namespace ActiveBasic
+	Function IsNothing(o As Object) As Boolean
+		Return Object.ReferenceEquals(o, Nothing)
+	End Function
+End Namespace
Index: trunk/Include/Classes/System/Exception.ab
===================================================================
--- trunk/Include/Classes/System/Exception.ab	(revision 385)
+++ trunk/Include/Classes/System/Exception.ab	(revision 385)
@@ -0,0 +1,638 @@
+'Classses/System/Exception.ab
+
+#require <Classes/ActiveBasic/misc.ab>
+
+'右のコメントは対応するCOR_E_ナントカのコード
+Const AB_E_EXCEPTION = &h80041500 '80131500
+Const AB_E_SYSTEM = &h80041501 '80131501
+Const AB_E_ARGUMENT = E_INVALIDARG '80070057
+Const AB_E_ARGUMENTOUTOFRANGE = E_INVALIDARG '80131502
+Const AB_E_INDEXOUTOFRANGE = &h80041508 '80131508
+Const AB_E_INVALIDOPERATION = &h80041509 '80131509
+Const AB_E_NOTSUPPORTED = &h80041515 '80131515
+Const AB_E_PLATFORMNOTSUPPORTED = &h80041539 '80131539
+
+/*
+現時点で不要そうなもの（System名前空間直下のもののみ）
+AccessViolationException
+ArrayTypeMismatchException
+ArithmeticException
+BadImageFormatException
+DataMisalignedException
+FormatException
+InvalidCastException
+
+当分（一部は未来永劫）不要そうなもの（System名前空間直下のもののみ）
+AppDomainUnloadedException
+CannotUnloadAppDomainException
+ExecutionEngineException
+InvalidProgramException
+MemberAccessException
+	FieldAccessException 
+	MethodAccessException 
+	MissingMemberException 
+MulticastNotSupportedException
+NullReferenceException
+OverflowException
+RankException
+StackOverflowException
+TypeInitializationException
+TypeLoadException
+TypeUnloadedException
+UnauthorizedAccessException
+*/
+
+Namespace System
+
+/*!
+@brief	例外クラスの基本クラス
+@author	Egtra
+@date	2007/11/16
+*/
+Class Exception
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub Exception()
+		init(GetType().FullName, Nothing)
+		hr = AB_E_EXCEPTION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub Exception(message As String)
+		init(message, Nothing)
+		hr = AB_E_EXCEPTION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub Exception(message As String, innerException As Exception)
+		init(message, innerException)
+		hr = AB_E_EXCEPTION
+	End Sub
+
+	'Methods
+
+	/*!
+	@brief	基本例外を返す
+	@return	最初に投げられた大本の例外
+	*/
+	Function GetBaseException() As Exception
+		GetBaseException = This
+		While ActiveBasic.IsNothing(GetBaseException.inner) = False
+			GetBaseException = GetBaseException.inner
+		Wend
+	End Function
+
+	/*!
+	@brief	文字列化する
+	@return	エラー内容を表す文字列
+	*/
+	Override Function ToString() As String
+		If Object.ReferenceEquals(toStr, Nothing) Then
+			Dim sb = New System.Text.StringBuilder
+			sb.Append(GetType().FullName).Append(": ")
+			sb.Append(Message)
+			toStr = sb.ToString
+		End If
+		Return toStr
+	End Function
+
+	'Properties
+
+	/*!
+	@brief	内部例外を返す
+	@return	これが保持している内部例外。無ければNothing。
+	*/
+	Function InnerException() As Exception
+		Return inner
+	End Function
+
+	/*!
+	@brief	エラーメッセージの取得
+	*/
+	Virtual Function Message() As String
+		Return msg
+	End Function
+
+	/*!
+	@brief	この例外に関連付けられたヘルプへのURLもしくはURNの設定
+	*/
+	Virtual Sub HelpLink(help As String)
+		helpLink = help
+	End Sub
+
+	/*!
+	@brief	この例外に関連付けられたヘルプへのURLもしくはURNの取得
+	*/
+	Virtual Function HelpLink() As String
+		Return helpLink
+	End Function
+
+	/*!
+	@brief	この例外の発生元のアプリケーションもしくはオブジェクトの設定
+	*/
+	Virtual Sub Source(source As String)
+		src = source
+	End Sub
+
+	/*!
+	@brief	この例外の発生元のアプリケーションもしくはオブジェクトの取得
+	*/
+	Virtual Function Source() As String
+		Return src
+	End Function
+Protected
+	/*!
+	@brief	HRESULT値の設定
+	*/
+	Sub HResult(hres As HRESULT)
+		hr = hres
+	End Sub
+
+	/*!
+	@brief	HRESULT値の取得
+	*/
+	Function HResult() As HRESULT
+		Return hr
+	End Function
+
+Private
+	Sub init(message As String, innerException As Exception)
+		msg = message
+		inner = innerException
+	End Sub
+
+	msg As String
+	toStr As String
+	inner As Exception
+	helpLink As String
+	src As String
+	hr As HRESULT
+End Class
+
+/*!
+@brief	システム定義の例外の基底クラス
+@author	Egtra
+@date	2007/11/17
+*/
+Class SystemException
+	Inherits Exception
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub SystemException()
+		Exception(GetType().FullName, Nothing)
+		HResult = AB_E_SYSTEM
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub SystemException(message As String)
+		Exception(message, Nothing)
+		HResult = AB_E_SYSTEM
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub SystemException(message As String, innerException As Exception)
+		Exception(message, innerException)
+		HResult = AB_E_SYSTEM
+	End Sub
+End Class
+
+/*!
+@brief	実引数に問題があることを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class ArgumentException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub ArgumentException()
+		SystemException("One or more arguments have invalid value.", Nothing)
+		HResult = AB_E_ARGUMENT
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub ArgumentException(message As String)
+		SystemException(message, Nothing)
+		HResult = AB_E_ARGUMENT
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub ArgumentException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = AB_E_ARGUMENT
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] paramName	原因となった仮引数名
+	*/
+	Sub ArgumentException(message As String, paramName As String)
+		SystemException(message, Nothing)
+		param = paramName
+		HResult = AB_E_ARGUMENT
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	@param[in] paramName	原因となった仮引数名
+	*/
+	Sub ArgumentException(message As String, paramName As String, innerException As Exception)
+		SystemException(message, innerException)
+		param = paramName
+		HResult = AB_E_ARGUMENT
+	End Sub
+
+	Override Function Message() As String
+		Dim sb = New System.Text.StringBuilder
+		sb.Append(param).Append(": ").Append(Super.Message)
+		Return sb.ToString
+	End Function
+
+	/*!
+	@brief	この例外の発生原因の仮引数名の取得
+	*/
+	Virtual Function Param() As String
+		Return param
+	End Function
+Private
+	param As String
+End Class
+
+/*!
+@brief	NothingまたはNULLを受け付けない引数にそれらが渡されたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class ArgumentNullException
+	Inherits ArgumentException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub ArgumentNullException()
+		ArgumentException("One or more arguments have Nothing or Null value.", "", Nothing)
+		HResult = E_POINTER
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub ArgumentNullException(message As String)
+		ArgumentException(message, "", Nothing)
+		HResult = E_POINTER
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub ArgumentNullException(message As String, innerException As Exception)
+		ArgumentException(message, "", innerException)
+		HResult = E_POINTER
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] paramName	原因となった仮引数名
+	*/
+	Sub ArgumentNullException(message As String, paramName As String)
+		ArgumentException(message, paramName)
+		HResult = E_POINTER
+	End Sub
+End Class
+
+/*!
+@brief	規定された範囲を超える実引数が渡されたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class ArgumentOutOfRangeException
+	Inherits ArgumentException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub ArgumentOutOfRangeException()
+		ArgumentException("One or more arguments ware out of range value.", "", Nothing)
+		HResult = AB_E_ARGUMENTOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub ArgumentOutOfRangeException(message As String)
+		ArgumentException(message, "", Nothing)
+		HResult = AB_E_ARGUMENTOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub ArgumentOutOfRangeException(message As String, innerException As Exception)
+		ArgumentException(message, "", innerException)
+		HResult = AB_E_ARGUMENTOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] paramName	原因となった仮引数名
+	*/
+	Sub ArgumentOutOfRangeException(message As String, paramName As String)
+		ArgumentException(message, paramName, Nothing)
+		HResult = AB_E_ARGUMENTOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] actualValue	問題となった仮引数の値
+	@param[in] paramName	原因となった仮引数名
+	*/
+	Sub ArgumentOutOfRangeException(message As String, actualValue As Object, paramName As String)
+		ArgumentException(message, paramName, Nothing)
+		actualValueObject = actualValue
+		HResult = AB_E_ARGUMENTOUTOFRANGE
+	End Sub
+
+	/*!
+	@brief	この例外の発生原因の実引数の値の取得
+	*/
+	Virtual Function ActualValue() As Object
+		Return actualValueObject
+	End Function
+
+	Override Function Message() As String
+		If ActiveBasic.IsNothing(actualValueObject) Then
+			Return Super.Message
+		Else
+			Dim sb = New System.Text.StringBuilder
+			sb.Append(Param).Append(" = ").Append(actualValueObject)
+			sb.Append(": ").Append(Super.Message)
+			Return sb.ToString
+		End If
+	End Function
+Private
+	actualValueObject As Object
+End Class
+
+/*!
+@brief	配列の範囲外の要素を読み書きしようとしたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class IndexOutOfRangeException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub IndexOutOfRangeException()
+		SystemException("The index was out of range value.", Nothing)
+		HResult = AB_E_INDEXOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub IndexOutOfRangeException(message As String)
+		SystemException(message, Nothing)
+		HResult = AB_E_INDEXOUTOFRANGE
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub IndexOutOfRangeException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = AB_E_INDEXOUTOFRANGE
+	End Sub
+End Class
+
+/*!
+@brief	無効な操作を行おうとしたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class InvalidOperationException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub InvalidOperationException()
+		SystemException("The operation is invalid.", Nothing)
+		HResult = AB_E_INVALIDOPERATION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub InvalidOperationException(message As String)
+		SystemException(message, Nothing)
+		HResult = AB_E_INVALIDOPERATION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub InvalidOperationException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = AB_E_INVALIDOPERATION
+	End Sub
+End Class
+
+/*!
+@brief	そのメソッド・関数ないし操作が実装されていないことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class NotImplementedException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub NotImplementedException()
+		SystemException("Not implemented.", Nothing)
+		HResult = E_NOTIMPL
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub NotImplementedException(message As String)
+		SystemException(message, Nothing)
+		HResult = E_NOTIMPL
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub NotImplementedException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = E_NOTIMPL
+	End Sub
+End Class
+
+/*!
+@brief	対応していないメソッド・関数ないし操作を行おうとしたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class NotSupportedException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub NotSupportedException()
+		SystemException("This operation is not supported,", Nothing)
+		HResult = AB_E_NOTSUPPORTED
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub NotSupportedException(message As String)
+		SystemException(message, Nothing)
+		HResult = AB_E_NOTSUPPORTED
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub NotSupportedException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = AB_E_NOTSUPPORTED
+	End Sub
+End Class
+
+/*!
+@brief	実行しているプラットフォームで対応していないメソッド・関数ないし操作を行おうとしたことを表す例外
+@author	Egtra
+@date	2007/11/19
+*/
+Class PlatformNotSupportedException
+	Inherits NotSupportedException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub PlatformNotSupportedException()
+		NotSupportedException("This operation is not supported in this platform.", Nothing)
+		HResult = AB_E_PLATFORMNOTSUPPORTED
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub PlatformNotSupportedException(message As String)
+		NotSupportedException(message, Nothing)
+		HResult = AB_E_PLATFORMNOTSUPPORTED
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub PlatformNotSupportedException(message As String, innerException As Exception)
+		NotSupportedException(message, innerException)
+		HResult = AB_E_PLATFORMNOTSUPPORTED
+	End Sub
+End Class
+
+/*!
+@brief	操作が取り止められたことを表す例外
+@author	Egtra
+@date	2007/11/19
+@todo	HResultの調査
+*/
+Class OperationCanceledException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub OperationCanceledException()
+		SystemException("The operation was canceled.", Nothing)
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub OperationCanceledException(message As String)
+		SystemException(message, Nothing)
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub OperationCanceledException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+	End Sub
+End Class
+
+/*!
+@brief	メモリ不足例外
+@author	Egtra
+@date	2007/11/19
+@todo	HResultの調査
+*/
+Class OutOfMemoryException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub OutOfMemoryException()
+		SystemException("Out of memory.", Nothing)
+		HResult = E_OUTOFMEMORY
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub OutOfMemoryException(message As String)
+		SystemException(message, Nothing)
+		HResult = E_OUTOFMEMORY
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub OutOfMemoryException(message As String, innerException As Exception)
+		SystemException(message, innerException)
+		HResult = E_OUTOFMEMORY
+	End Sub
+End Class
+
+
+End Namespace
Index: trunk/Include/Classes/System/Text/StringBuilder.ab
===================================================================
--- trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 384)
+++ trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 385)
@@ -120,14 +120,5 @@
 
 	Function Append(s As String, startIndex As Long, count As Long) As StringBuilder
-		If s = 0 Then
-			If startIndex = 0 And count = 0 Then
-				Return This
-			Else
-				'Throw ArgumentNullException
-			End If
-		End If
-		StringBuilder.rangeCheck2(s.Length, startIndex, count)
-		appendCore(s, startIndex, count)
-		Return This
+		Return Append(StrPtr(s), startIndex, count)
 	End Function
 
@@ -137,8 +128,8 @@
 				Return This
 			Else
-				'Throw ArgumentNullException
+				Throw New ArgumentNullException("StringBuilder.Append: An argument was null", "s")
 			End If
 		ElseIf startIndex < 0 Or count < 0 Then
-			'Throw ArgumentOutOfRangeException
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "startIndex or count or both")
 		End If
 		appendCore(s, startIndex, count)
@@ -178,7 +169,7 @@
 	Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)
 		If dest = 0 Then
-			'Throw ArgumentNullException
+			Throw New ArgumentNullException("StringBuilder.CopyTo: An argument was null", "sourceIndex")
 		ElseIf size < sourceIndex + count Or sourceIndex < 0 Or destIndex < 0 Or count < 0 Then
-			'Throw ArgumentOutOfRangeException
+			Throw New ArgumentOutOfRangeException("StringBuilder.CopyTo: One or more arguments have out of range value.", "startIndex or count or both")
 		End If
 
@@ -188,5 +179,5 @@
 	Function EnsureCapacity(c As Long) As Long
 		If c < 0 Or c > MaxCapacity Then
-			'Throw ArgumentOutOfRangeException
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument was out of range value.", "c")
 		ElseIf c > Capacity Then
 			Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar
@@ -300,6 +291,5 @@
 		rangeCheck(index)
 		If n < 0 Then
-			'Throw New ArgumentOutOfRangeException
-			Debug
+			Throw New ArgumentOutOfRangeException("StringBuilder.Insert: An argument was out of range value.", "n")
 		End If
 		Dim len = x.Length
@@ -308,7 +298,4 @@
 		EnsureCapacity(newSize)
 		separateBuffer()
-
-		' TODO: fix me!（定義されていない変数iが使われています）
-		'ActiveBasic.Strings.ChrMove(VarPtr(chars[i + lenTotal]), VarPtr(chars[i]), (size - index) As SIZE_T)
 
 		Dim i As Long
@@ -320,13 +307,10 @@
 	End Function
 
-
 	Function Insert(i As Long, x As *StrChar, index As Long, count As Long) As StringBuilder
 		rangeCheck(i)
 		If x = 0 Then
-			'Throw New ArgumentNullException
-			Debug
+			Throw New ArgumentNullException("StringBuilder.Insert: An argument was null", "x")
 		ElseIf index < 0 Or count < 0 Then
-			'Throw New ArgumentNullException
-			Debug
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "index or count or both")
 		End If
 
@@ -396,10 +380,8 @@
 
 	Sub replaceCore(oldStr As String, newStr As String, start As Long, count As Long)
-		If Object.ReferenceEquals(oldStr, Nothing) Then
-			'Throw ArgumentNullException
-			Debug
+		If ActiveBasic.IsNothing(oldStr) Then
+			Throw New ArgumentNullException("StringBuilder.Replace: An argument was null", "oldStr")
 		ElseIf oldStr.Length = 0 Then
-			'Throw ArgumentException
-			Debug
+			Throw New ArgumentException("StringBuilder.Replace: The argument 'oldStr' is empty string. ", "oldStr")
 		End If
 
@@ -412,7 +394,7 @@
 			End If
 			
-			s.appendCore(chars, curPos, nextPos)
+			s.appendCore(chars, curPos, nextPos As Long)
 			s.Append(newStr)
-			curPos += nextPos + oldStr.Length
+			curPos += nextPos As Long + oldStr.Length
 		Loop
 		chars = s.chars
@@ -446,5 +428,5 @@
 	Sub Capacity(c As Long)
 		If c < size Or c > MaxCapacity Then 'sizeとの比較でcが負の場合も対応
-			'Throw ArgumentOutOfRangeException
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument have out of range value.", "c")
 		End If
 		EnsureCapacity(c)
@@ -453,6 +435,5 @@
 	Const Function Chars(i As Long) As StrChar
 		If i >= Length Or i < 0 Then
-			'Throw IndexOutOfRangeException
-			Debug
+			Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' have out of range value.")
 		End If
 		Return chars[i]
@@ -461,6 +442,5 @@
 	Sub Chars(i As Long, c As StrChar)
 		If i >= Length Or i < 0 Then
-			'Throw ArgumentOutOfRangeException
-			Debug
+			Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument have out of range value.", "i")
 		End If
 		chars[i] = c
@@ -494,5 +474,5 @@
 	Sub initialize(capacity As Long, maxCapacity = LONG_MAX As Long)
 		If capacity < 0 Or maxCapacity < 1 Or maxCapacity < capacity Then
-			'Throw ArgumentOutOfRangeException
+			Throw New ArgumentOutOfRangeException("StringBuilder constructor: One or more arguments have out of range value.", "capacity or maxCapacity or both")
 		End If
 
@@ -526,6 +506,5 @@
 	Sub rangeCheck(index As Long)
 		If index < 0 Or index > size Then
-			'Throw ArgumentOutOfRangeException
-			Debug
+			Throw New ArgumentOutOfRangeException("StringBuilder: Index argument has out of range value.")
 		End If
 	End Sub
@@ -538,6 +517,5 @@
 		'length < 0は判定に入っていないことに注意
 		If startIndex < 0 Or count < 0 Or startIndex + count > length Then
-			'Throw ArgumentOutOfRangeException
-			Debug
+			Throw New ArgumentOutOfRangeException("StringBuilder: One or more arguments have out of range value.", "startIndex or count or both")
 		End If
 	End Sub
Index: trunk/Include/Classes/index.ab
===================================================================
--- trunk/Include/Classes/index.ab	(revision 384)
+++ trunk/Include/Classes/index.ab	(revision 385)
@@ -1,2 +1,3 @@
+#require "./ActiveBasic/misc.ab"
 #require "./ActiveBasic/Core/InterfaceInfo.ab"
 #require "./ActiveBasic/Core/TypeInfo.ab"
@@ -11,4 +12,5 @@
 #require "./System/Delegate.ab"
 #require "./System/Environment.ab"
+#require "./System/Exception.ab"
 #require "./System/GC.ab"
 #require "./System/Math.ab"
Index: trunk/Include/basic/function.sbp
===================================================================
--- trunk/Include/basic/function.sbp	(revision 384)
+++ trunk/Include/basic/function.sbp	(revision 385)
@@ -427,30 +427,28 @@
 End Function
 
-Dim _System_ecvt_buffer[16] As StrChar
-Sub _ecvt_support(count As Long)
+Sub _ecvt_support(buf As *StrChar, count As Long, size As Long)
 	Dim i As Long
-	If _System_ecvt_buffer[count]=9 Then
-		_System_ecvt_buffer[count]=0
-		If count=0 Then
-			For i=16 To 1 Step -1
-				_System_ecvt_buffer[i]=_System_ecvt_buffer[i-1]
+	If buf[count] = 9 Then
+		buf[count] = 0
+		If count = 0 Then
+			For i = size To 1 Step -1
+				buf[i] = buf[i-1]
 			Next
-			_System_ecvt_buffer[0]=1
+			buf[0] = 1
 		Else
-			_ecvt_support(count-1)
-		End If
-	Else
-		_System_ecvt_buffer[count]++
+			_ecvt_support(buf, count-1, size)
+		End If
+	Else
+		buf[count]++
 	End If
 End Sub
-Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar
+
+Sub _ecvt(buffer As *StrChar, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean)
 	Dim i As Long, i2 As Long
-
-	_ecvt=_System_ecvt_buffer
 
 	'値が0の場合
 	If value = 0 Then
-		ActiveBasic.Strings.ChrFill(_System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)
-		_System_ecvt_buffer[count] = 0
+		ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As StrChar)
+		buffer[count] = 0
 		dec = 0
 		sign = 0
@@ -460,8 +458,8 @@
 	'符号の判断（同時に符号を取り除く）
 	If value < 0 Then
-		sign = 1
+		sign = True
 		value = -value
 	Else
-		sign = 0
+		sign = False
 	End If
 
@@ -477,22 +475,20 @@
 	Wend
 
-	For i=0 To count-1
-		_System_ecvt_buffer[i] = Int(value) As StrChar
-
+	For i = 0 To count - 1
+		buffer[i] = Int(value) As StrChar
 		value = (value-CDbl(Int(value))) * 10
 	Next
-	_System_ecvt_buffer[i] = 0
 
 	i--
 	If value >= 5 Then
 		'切り上げ処理
-		_ecvt_support(i)
-	End If
-
-	For i=0 To ELM(count)
-		_System_ecvt_buffer[i] += &H30
+		_ecvt_support(buffer, i, count)
+	End If
+
+	For i = 0 To count - 1
+		buffer[i] += &H30
 	Next
-	_System_ecvt_buffer[i] = 0
-End Function
+	buffer[i] = 0
+End Sub
 
 Function Str$(dbl As Double) As String
@@ -506,12 +502,10 @@
 		End If
 	End If
-	Dim dec As Long, sign As Long
-	Dim buffer[32] As StrChar, temp As *StrChar
-	Dim i As Long, i2 As Long, i3 As Long
+	Dim dec As Long, sign As Boolean
+	Dim buffer[32] As StrChar, temp[15] As StrChar
+	Dim i = 0 As Long
 
 	'浮動小数点を文字列に変換
-	temp = _ecvt(dbl, 15, dec, sign)
-
-	i=0
+	_ecvt(temp, dbl, 15, dec, sign)
 
 	'符号の取り付け
@@ -521,6 +515,6 @@
 	End If
 
-	If dec>15 Then
-		'指数表示（桁が大きい場合）
+	If dec > 15 Or dec < -3 Then
+		'指数表示
 		buffer[i] = temp[0]
 		i++
@@ -529,29 +523,11 @@
 		ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
 		i += 14
-		buffer[i] = Asc("e")
-		i++
-		_stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応
-
-		Return MakeStr(buffer)
-	End If
-
-	If dec < -3 Then
-		'指数表示（桁が小さい場合）
-		buffer[i] = temp[0]
-		i++
-		buffer[i] = Asc(".")
-		i++
-		ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
-		i+=14
-		buffer[i] = Asc("e")
-		i++
-		_stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応
-
-		Return MakeStr(buffer)
+		buffer[i] = 0
+		Return MakeStr(buffer) + ActiveBasic.Strings.SPrintf("e%+03d", New System.Int32(dec - 1))
 	End If
 
 	'整数部
-	i2=dec
-	i3=0
+	Dim i2 = dec
+	Dim i3 = 0
 	If i2>0 Then
 		While i2>0
@@ -593,79 +569,38 @@
 End Function
 
-Function Str$(i As Int64) As String
-	If i < 0 Then
-		Return "-" & Str$(-i As QWord)
-	Else
-		Return Str$(i As QWord)
-	End If
+Function Str$(x As Int64) As String
+	Imports ActiveBasic.Strings.Detail
+	Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None)
 End Function
 
 Function Str$(x As QWord) As String
-	If x = 0 Then
-		Return "0"
-	End If
-
-	Dim buf[20] As StrChar
-	'buf[20] = 0
-	Dim i = 19 As Long
-	Do
-		buf[i] = (x Mod 10 + &h30) As StrChar
-		x \= 10
-		If x = 0 Then
-			Exit Do
-		End If
-		i--
-	Loop
-	Return New String(VarPtr(buf[i]), 20 - i)
+	Imports ActiveBasic.Strings.Detail
+	Return FormatIntegerEx(TraitsIntegerU[1], x, 1, 0, None)
 End Function
 
 Function Str$(x As Long) As String
-#ifdef _WIN64
-	Return Str$(x As Int64)
-#else
-	If x < 0 Then
-		Return "-" & Str$(-x As DWord)
-	Else
-		Return Str$(x As DWord)
-	End If
-#endif
+	Imports ActiveBasic.Strings.Detail
+	Return FormatIntegerEx(TraitsIntegerD[0], x, 1, 0, None)
 End Function
 
 Function Str$(x As DWord) As String
-#ifdef _WIN64
-	Return Str$(x As QWord)
-#else
-	If x = 0 Then
-		Return "0"
-	End If
-
-	Dim buf[10] As StrChar
-	buf[10] = 0
-	Dim i = 9 As Long
-	Do
-		buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策
-		x \= 10
-		If x = 0 Then
-			Return New String(VarPtr(buf[i]), 10 - i)
-		End If
-		i--
-	Loop	
-#endif
+	Imports ActiveBasic.Strings.Detail
+	Return FormatIntegerEx(TraitsIntegerU[0], x, 1, 0, None)
 End Function
 
 Function Str$(x As Word) As String
-	Return Str$(x As ULONG_PTR)
+	Return Str$(x As DWord)
 End Function
 
 Function Str$(x As Integer) As String
-	Return Str$(x As LONG_PTR)
+	Return Str$(x As Long)
 End Function
 
 Function Str$(x As Byte) As String
-	Return Str$(x As ULONG_PTR)
+	Return Str$(x As DWord)
 End Function
 
 Function Str$(x As SByte) As String
-	Return Str$(x As LONG_PTR)
+	Return Str$(x As Long)
 End Function
 
Index: trunk/Include/system/string.sbp
===================================================================
--- trunk/Include/system/string.sbp	(revision 384)
+++ trunk/Include/system/string.sbp	(revision 385)
@@ -9,5 +9,7 @@
 
 Function StrPtr(s As String) As *StrChar
-	StrPtr = s.StrPtr
+	If ActiveBasic.IsNothing(s) Then
+		StrPtr = s.StrPtr
+	End If
 End Function
 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
@@ -39,7 +41,7 @@
 Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
 	If psz = 0 Then Return 0
-	Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, len As Long, 0, 0)
+	Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0)
 	wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
-	GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, len As Long, wcs, lenWCS)
+	GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS)
 	wcs[GetStr] = 0
 End Function
@@ -73,7 +75,7 @@
 Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
 	If psz = 0 Then Return 0
-	Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, len As Long, 0, 0, 0, 0)
+	Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0)
 	mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
-	GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, len As Long, mbs, lenMBS, 0, 0) As SIZE_T
+	GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T
 	mbs[GetStr] = 0
 End Function
