I added Tim Parnell’s TPSF class for specialfolders to my project. I would like to add error / exception handling to this class, but, not understanding classes well, I don’t know how to begin trapping for the error. There also isn’t something obvious in the XOJO insert menu. It also probably should go in the class as opposed to the app.
How do I do this?
I tried a basic search in the forum for “error class” and of course came up with an overwhelming number. I also tried to search in my RB Developer (only thru 8.6) and had the same problem.
Understanding classes is a crucial skill for Xojo development.
For trapping errors:
- Add a new class and give it the name “ErrorException”.
- Give the new class a constructor with the parameters theError as RuntimeException, Location as string .
- Do your error handling in the constructor. I collect data about the exception, show the user a nice window which offers to send me a mail with crash reports and session logs.
- In a method of your choosing add
exception exc
theException = new ErrorException(exc, currentMethodName)
at the bottom. This needs to go to every method, by the way, if you want to implement error handling in all of your code.
- The final step is to test your error handling by adding “raise new NilObjectException” somewhere in your method.
Thank you, Beatrix. I appreciate this info and will add that class and constructors to my app.
I apologize for not using a correct word. TPSF is a module not class.
I can’t see how to apply this exactly because these are folderitems that usually do exist.
One of his methods, for instance, is
[code]Protected Function AppSupport() as FolderItem
dim fReturn as FolderItem = SpecialFolder.ApplicationData
// Prevent NOEs
if fReturn = nil then return nil
#if TargetMacOS then
return fReturn.Child(App.BundleIdentifier)
#elseif TargetWin32 then
return fReturn.Child(ThisAppName)
#elseif TargetLinux then
return fReturn.Child("." + ThisAppName)
#endif
End Function
[/code]
How do I separate out this error from the normal folderitem error?
The code
exception exc
theException = new ErrorException(exc, currentMethodName)
goes into all modules, classes and windows of your project.
Perhaps I misunderstood your question. What do you want to do with the TPSF code?
Replace this code
// Prevent NOEs
if fReturn = nil then return nil
with your error handling.
Alternately, check for nil after you call TPSF and report an error from your code.
I probably need to ask this in another question because it’s more about TPSF methods than error handling, but I’ll try anyways.
I need to add something to TPSF a SpecialFolder that’s a subfolder or property. For ease of explaining and not complicating the issue, I have a preferences file that might not be loaded, but usually is. That in itself I have no problem with handling if it isn’t, but not with object code.
TPSF however has 2 methods at least that return
return App.ExecutableFile.Parent
The methods are Contents and BundleParent and I don’t know the difference between them. These methods are necessary I guess. So, my confusion is 2 parts.
Part 1. Design of more methods for SpecialFolders object returns. I don’t know if I have to add/design some other methods that are seemingly double for Attributes of SpecialFolders. I also don’t know how to ensure that a method for something like a SpecialFolder will be called. This is different from the recentitems example, which uses an array. I don’t know of an example which returns a folderitem? How do I design this part?
Part 2. Error handling for multiple and seemingly duplicate methods that are also optional. If it was a normal test and only 1 method returning, I could add code to the method for an error. How do handle something which is optional (normally this might cause premature application closing) but has 2 methods to account for?
-
if you use third party code and hope to every update it with a newer release of that third party code then dont alter it
Add your extra stuff elsewhere (in your own modules) that USES the TPSF code as part if how it does what it does
If you add your own methods in there then when / if its updated you have to go through method by method and pull in the new stuff -
use TPSF as the foundation for whatever it is your code needs to do specially
Absolutely Norm. My problem is I don’t know what to add. I don’t have examples of object code returning folderitems. (I think he also intends for it to be extended)
Are there examples of returning of folderitems ?
Never mind. I assumed that my app would at one time or other access either of the lines, but according to the debugger they aren’t.