Add Distribution Fitting & Simulation Features to Your Applications |
||||||||||||||||||||||||||||||||||||||||||
SPA SDK Help Home • Learn More About the SPA SDK | ||||||||||||||||||||||||||||||||||||||||||
Error HandlingThe SPA SDK supports the standard COM error handling mechanism. Many object member functions can return error codes which should be handled by your application. The error handling technique can vary depending on the development platform used - VBA, C#, VB.NET, C++.NET, or unmanaged C++. Error Handling in Visual Basic for ApplicationsIn VBA, you can use the Err.Number property to extract the error code returned by the SDK: Dim data() As Double ' set error handler On Error GoTo ErrHandler Call dist.RandomArray(-100, data) ' dist has the type SPADistribution Exit Sub ' error handler ErrHandler: If Err.Number = SPAEInvalidDist Then MsgBox "Invalid distribution type or parameters" ElseIf Err.Number = SPAEInvalidArg Then MsgBox "Invalid function arguments" Else MsgBox "Some other error occured" End If Error Handling in .NET (C#, VB.NET, C++.NET)In .NET languages, you can use the try/catch block and the standard System.Exception class to obtain the error information. Since the numerical COM error codes are not available through this class, the SDK returns the codes as strings via the Message property. For instance, the typical C# error handling code will be as follows: try { double[] r = null; dist.RandomArray(-250, ref r); // dist has type SPADistribution Console.WriteLine(r.Length); } catch (Exception e) { SPAErrorType error = (SPAErrorType)Convert.ToInt32(e.Message); switch (error) { case SPAErrorType.SPAEInvalidDist: Console.WriteLine("Invalid distribution type or parameters"); break; case SPAErrorType.SPAEInvalidArg: Console.WriteLine("Invalid function arguments"); break; default: Console.WriteLine("Some other error occured"); break; } } Error Handling in C++ (unmanaged)In native C++, the error information can be retrieved using the try/catch block and the standard _com_error class. To extract the numerical error code, you should convert the return value of the _com_error::Description() member function to integer: try { SAFEARRAY *randomData = NULL; dist->RandomArray(-100, &randomData); // dist has type ISPADistribution* } catch (_com_error &err) { switch (atol(err.Description())) { case SPAErrorType::SPAEInvalidDist: printf ("Invalid distribution type or parameters\n"); break; case SPAErrorType::SPAEInvalidArg: printf ("Invalid function arguments\n"); break; default: printf ("Some other error occured\n"); } } Error CodesThe SPAErrorType enumeration includes all the error codes supported by the SDK:
|
||||||||||||||||||||||||||||||||||||||||||
Copyright © MathWave Technologies www.mathwave.com |