I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
I have to apologize that after all this error handling banter I really don't know what the issue is.
As someone (Peter Judge?) had answered in the prior conversation (that I can't see here) you should make sure there is an error message in your AppErrors by passing 2 parameters to the constructor (message and #) or using the AddMessage method. Then you can always get the message with GetMessage. Why would you care about ReturnValue? That is only really there for backward compatibility with non-structured error handling.
The Error interface will work for all error types, including .NET exceptions. You can have a single catch block or more than one. If you only have one you can always test the type of the actual error object you got if you need to get extra information from that specific type - like ReturnValue if you still want to use that. You can have both a ReturnValue and an error message in the same AppError.
So what's the question/problem?
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
Flag this post as spam/abuse.
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Are you saying that if I include an error number in addition to the message when throwing an AppError, that it will show up in GetMessages? I thought I tried that and did *not* get anything.
Correct. There are two different AppError constructors, one that just takes a message (which sets ReturnValue) and the other that takes a message and a # (don't remember in which order). This sets an error message and a message #. And regardless of which constructor you use, you can always add a message or set a ReturnValue by using the other methods and properties of AppError.
Are you saying that if I include an error number in addition to the message when throwing an AppError, that it will show up in GetMessages? I thought I tried that and did *not* get anything.
Flag this post as spam/abuse.
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
I keep learning more about error handling ... by discovering things that I didn't know.
I started out my current project with catch blocks for AppError and SysError. The former logging ReturnValue and the latter logging GetMessages and the CallStack. Then, because of .NET errors from Proparse, it was suggested that I add a catch block for just Error which also included GetMessages and CallStack. This seemed to help.
But, now some new questions.
Having gone back to the manual because of some issues, I see that Error is an interface, not a superclass. So, I'm wondering if my third catch block above shouldn't be for ProError instead. Would it make any difference?
I am currently doing some little batch utilities which don't have all the logging of the main project. So, I thought I would just put in a simple catch block for Error and dump the GetMessages and CallStack to the output file in the unlikely event that something went wrong. But, I find that GetMessages doesn't give one the ReturnValue if I throw an AppError. So, does this mean that I need at least two catch blocks for AppError and Error (or ProError)? Or do I actually need all three?
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
Flag this post as spam/abuse.
To answer the original question:
ProError is the super class for AppError and SysError, but not for other errors, e.g. .Net errors.
But all errors implements the Error interface.
So you can catch the AppError and use its ReturnValue and/or any messages it contains, followed by catching the Error interface to catch anything else that is left.
Alternatively you can catch the Error interface only. If it has no messages, you can test if it is an AppError and if so, cast it and check for a ReturnValue.
I do not quite comprehend why the two AppError contructors cause you to always end up without a message somewhere, as it always complicates things and leads to unnatural code, e.g. "NEW AppError('My messages', any0meaningless-integer)" just to get the "new" structured error handling to work.
For compatibility with traditional errors, I would expect that the ReturnValue property's getter should simply map to GetMessage(1) and that it would either be a) ReadOnly, or b) have a setter that either insert the message in the first position or clear all other messages and insert only the supplied message. This would also enabled us to use structured error handling while still using the more productive, simpler to read, easy to type, RETURN ERROR "Some message" to raise the AppError, which would be closer to the life long philosophy of PSC to produce a 4GL where the programmer focus on what, not how, something happens.
To answer the original question:
ProError is the super class for AppError and SysError, but not for other errors, e.g. .Net errors.
But all errors implements the Error interface.
So you can catch the AppError and use its ReturnValue and/or any messages it contains, followed by catching the Error interface to catch anything else that is left.
Alternatively you can catch the Error interface only. If it has no messages, you can test if it is an AppError and if so, cast it and check for a ReturnValue.
I do not quite comprehend why the two AppError contructors cause you to always end up without a message somewhere, as it always complicates things and leads to unnatural code, e.g. "NEW AppError('My messages', any0meaningless-integer)" just to get the "new" structured error handling to work.
For compatibility with traditional errors, I would expect that the ReturnValue property's getter should simply map to GetMessage(1) and that it would either be a) ReadOnly, or b) have a setter that either insert the message in the first position or clear all other messages and insert only the supplied message. This would also enabled us to use structured error handling while still using the more productive, simpler to read, easy to type, RETURN ERROR "Some message" to raise the AppError, which would be closer to the life long philosophy of PSC to produce a 4GL where the programmer focus on what, not how, something happens.
Flag this post as spam/abuse.
Right, Laura, it doesn't have to be meaningless, but unless one commits to a systematic program of creating numbers, it will be meaningless and I find that disturbing because it is deceptive. I would have been much happier had AppError always set a message and ReturnValue produced the same result as GetMessage(1).
But, Simon's discussion has clarified things for me. The context in which the question arose is a routine using Proparse so appropriate sprinkling of Error is appropriate to catch anything Proparse does. Now that I have found an occasion to also throw an AppError, the simple thing is to add a catch block for that and avoid testing and casting and branching.
We use the error number extensively as we have an error message table that allows our end users to customize the error.
We use the error number extensively as we have an error message table that allows our end users to customize the error.
Flag this post as spam/abuse.
Exactly....we deal with retailers. You sometimes have to hit a cashier over the head to get them to understand.
[quote user="Laura Stern"]
Laura SternYou said:I do not quite comprehend why the two AppError contructors cause you to always end up without a message.This is not really fair. Actually there are 3 constructors. One takes no parameters and you need to set ReturnValue via the property or add a message with the AddMessage method to get one or the other.Of the other 2, as I said previously, AppError(<RetVal>) sets ReturnValue and the other AppError(<msg>, <msgNum>) sets the message.However, I agree entirely that it was a mistake to make the one-parameter, more obvious usage set the ReturnValue rather than the error message. This has been the source of much confusion.
Flag this post as spam/abuse.
Evan, what would prevent returning the RETURN-VALUE for an AppError in response to Get-Messages(1) instead of the latter returning nothing?
Evan, what would prevent returning the RETURN-VALUE for an AppError in response to Get-Messages(1) instead of the latter returning nothing?
Flag this post as spam/abuse.
Evan, what would prevent returning the RETURN-VALUE for an AppError in response to Get-Messages(1) instead of the latter returning nothing?
Flag this post as spam/abuse.