Browse Source

* Use correct exception class: Patch from Simon Ameis (bug ID 29961)

git-svn-id: trunk@34496 -
michael 9 years ago
parent
commit
6798504842
1 changed files with 26 additions and 10 deletions
  1. 26 10
      packages/rtl-objpas/src/inc/convutil.inc

+ 26 - 10
packages/rtl-objpas/src/inc/convutil.inc

@@ -26,12 +26,16 @@ interface
 {$H+}
 {$H+}
 
 
 {$ifndef FPUNONE}
 {$ifndef FPUNONE}
+uses
+  sysutils;
+
 Type TConvType        = type Integer;
 Type TConvType        = type Integer;
      TConvFamily      = type Integer;
      TConvFamily      = type Integer;
      TConvFamilyArray = array of TConvFamily;
      TConvFamilyArray = array of TConvFamily;
      TConvTypeArray   = array of TConvType;
      TConvTypeArray   = array of TConvType;
      TConversionProc  = function(const AValue: Double): Double;
      TConversionProc  = function(const AValue: Double): Double;
      TConvUtilFloat   = double;
      TConvUtilFloat   = double;
+     EConversionError = class(EConvertError);
 
 
 Function RegisterConversionFamily(Const S : String):TConvFamily;
 Function RegisterConversionFamily(Const S : String):TConvFamily;
 Function RegisterConversionType(Fam:TConvFamily;Const S:String;Value:TConvUtilFloat):TConvType;
 Function RegisterConversionType(Fam:TConvFamily;Const S:String;Value:TConvUtilFloat):TConvType;
@@ -84,6 +88,9 @@ Type
 
 
 Implementation
 Implementation
 
 
+uses
+  RtlConsts;
+
 Type ResourceData = record
 Type ResourceData = record
                       Description : String;
                       Description : String;
                       Value       : TConvUtilFloat;
                       Value       : TConvUtilFloat;
@@ -176,7 +183,8 @@ Function RegisterConversionType(Fam:TConvFamily;Const S:String;Value:TConvUtilFl
 var l1 : Longint;
 var l1 : Longint;
 
 
 begin
 begin
-  If NOT CheckFamily(Fam) Then exit(-1); // family not registered.
+  If NOT CheckFamily(Fam) Then
+    raise EConversionError.CreateFmt(SConvUnknownFamily, [IntToStr(Fam)]);
   if (value+1.0)<macheps then            // not properly defined yet.
   if (value+1.0)<macheps then            // not properly defined yet.
     exit(-1);
     exit(-1);
   l1:=length(theunits);
   l1:=length(theunits);
@@ -206,11 +214,14 @@ var
 
 
 begin
 begin
   if not SearchConvert(fromtype,fromrec) then
   if not SearchConvert(fromtype,fromrec) then
-   exit(-1.0);                                  // raise exception?
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(FromType)]);
   if not SearchConvert(totype,torec) then
   if not SearchConvert(totype,torec) then
-   exit(-1.0);                                  // raise except?
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(ToType)]);
   if fromrec.fam<>torec.fam then
   if fromrec.fam<>torec.fam then
-   exit(-1.0);
+    raise EConversionError.CreateFmt(SConvIncompatibleTypes2,[
+      ConvFamilyToDescription(fromrec.fam),
+      ConvFamilyToDescription(torec.fam)
+    ]);
   result:=Measurement*fromrec.value/torec.value;
   result:=Measurement*fromrec.value/torec.value;
 end;
 end;
 
 
@@ -221,15 +232,20 @@ var
 
 
 begin
 begin
   if not SearchConvert(fromtype1,fromrec1) then
   if not SearchConvert(fromtype1,fromrec1) then
-   exit(-1.0);                                  // raise exception?
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(fromtype1)]);
   if not SearchConvert(totype1,torec1) then
   if not SearchConvert(totype1,torec1) then
-   exit(-1.0);                                  // raise except?
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(totype1)]);
   if not SearchConvert(fromtype2,fromrec2) then
   if not SearchConvert(fromtype2,fromrec2) then
-   exit(-1.0);                                  // raise exception?
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(fromtype2)]);
   if not SearchConvert(totype2,torec2) then
   if not SearchConvert(totype2,torec2) then
-   exit(-1.0);                                  // raise except?
-  if (fromrec1.fam<>torec1.fam) or (fromrec1.fam<>torec1.fam) then
-   exit(-1.0);
+    raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(totype2)]);
+  if (fromrec1.fam<>torec1.fam) or (fromrec2.fam<>torec2.fam) then
+    raise EConversionError.CreateFmt(SConvIncompatibleTypes4,[
+      ConvFamilyToDescription(fromrec1.fam),
+      ConvFamilyToDescription(torec1.fam),
+      ConvFamilyToDescription(fromrec2.fam),
+      ConvFamilyToDescription(torec2.fam)
+    ]);
   result:=Measurement*(fromrec1.value/fromrec2.value)/(torec1.value/torec2.value);
   result:=Measurement*(fromrec1.value/fromrec2.value)/(torec1.value/torec2.value);
 end;
 end;