[mapguide-internals] Exception Handling in Init Coord System -
Patch for CoordSysCatalog
UV
uvwild at gmail.com
Fri Apr 24 08:37:55 EDT 2009
I just found the place in the code which properly frustrated most
novices so far.....
Very good explanation of why to catch the exception ... but utterly
wrong in its effect for too many use cases.
We have 2 main user groups... the big one using defaults and the others.
The choice made to suppress all exception information for most users
so the the small user group not needing this information does not have
to see it is wrong IMHO.
The messages need to be shown so we know whats happening.
The current exception handling is really frustrating as it ommits all
useful info and says.... Not Working.
I added some ACE_DEBUG level messages to CoordSysCatalog..... I did not
manage to print the used Directory path into the logfile.... so any
input is appreciated.
cheers
------------------------------------------------------------------------------------------------------------------------
CoordSysCatalog.cpp:#89
try
{
SetDefaultDictionaryDirAndFileNames();
}
catch (MgException* pEPath)
{
//We do not throw this exception because:
//- we might just not care about the default values
//of the directory and file names.
//They can very well be setup later on by the client
//- or the client might just not care about them because the
dictionaries are
//being compiled using an interface such as
MgCoordinateSystemDictionaryUtility
//- if we throw here, the constructor aborts and the factory
constructor aborts as well
//for something we can resolve later on (2 reasons described above)
SAFE_RELEASE(pEPath);
m_sDir=L"";
//internal API value needed for the server's initialization
which relies
//on the default values being setup automatically
m_libraryStatus=lsInitializationFailed;
}
-------------- next part --------------
Index: CoordSysCatalog.cpp
===================================================================
--- CoordSysCatalog.cpp (revision 3837)
+++ CoordSysCatalog.cpp (working copy)
@@ -100,6 +100,8 @@
//being compiled using an interface such as MgCoordinateSystemDictionaryUtility
//- if we throw here, the constructor aborts and the factory constructor aborts as well
//for something we can resolve later on (2 reasons described above)
+ ACE_DEBUG((LM_DEBUG, L"(%t) %W caught in Coord Init - %W\n", pEPath->GetClassName(), pEPath->GetDetails()));
+ /// now we have shared the info.... now we can get rid of the exception
SAFE_RELEASE(pEPath);
m_sDir=L"";
@@ -183,8 +185,6 @@
bool bResult=false;
#ifdef _WIN32
- //prepares the default path for dictionary failes
- STRING sDirDefault;
// Check to see if the environment variable is set
const TCHAR* szPathVar = _tgetenv(_T(MENTOR_DICTIONARY_PATH));
@@ -192,13 +192,19 @@
//if not set then try the default location
if(!szPathVar)
{
+ ACE_DEBUG((LM_DEBUG, ACE_TEXT("\n(%t) CCoordinateSystemCatalog::GetDefaultDictionaryDir() - environment variable MENTOR_DICTIONARY_PATH not set.\n")));
+
TCHAR szPath[MAX_PATH];
if(SHGetSpecialFolderPath(NULL, szPath, CSIDL_COMMON_APPDATA, FALSE))
{
- sDirDefault = szPath;
+ //the default path for dictionary failes
+ STRING sDirDefault = szPath;
sDirDefault += _T("\\Autodesk\\Geospatial Coordinate Systems"); //NOXLATE
szPathVar = sDirDefault.c_str();
- }
+ }
+ //else {
+ // ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) CCoordinateSystemCatalog::GetDefaultDictionaryDir() - Could not read SpecialFolderPath from registry\n")));
+ //}
}
if(szPathVar)
@@ -223,10 +229,15 @@
}
#endif
+ if (!MgFileUtil::IsDirectory(sDir.c_str()))
+ {
+ bResult = false;
+ ACE_DEBUG((LM_DEBUG, "(%t) DefaultDir: \"%W\" is not a directory! Deploy CoordinateSystems into this directory or\nset MENTOR_DICTIONARY_PATH to the current installation or else\n", new STRING(sDir)));
+ }
if (!bResult)
{
- throw new MgCoordinateSystemInitializationFailedException(L"MgCoordinateSystemCatalog.GetDefaultDictionaryDir", __LINE__, __WFILE__, NULL, L"", NULL);
+ throw new MgCoordinateSystemInitializationFailedException(L"MgCoordinateSystemCatalog.GetDefaultDictionaryDir ", __LINE__, __WFILE__, NULL, L"", NULL);
}
//And return success.
More information about the mapguide-internals
mailing list