 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marcel Guest
|
Posted: Thu Sep 23, 2004 9:02 am Post subject: Exception handling |
|
|
Imagine the method of my Active Server Object which will throw an exception
when _ansicodepage is 'XXX'. The function is part of my Active Server Object
which methods are called from an ASP page. I was asking myself why this
exception does not print out 'Ansicodepage is XXX' in the users browser
whenever the method is called like CBuilderObject.setAnsiCodePage "XXX" from
the ASP page (so _ansicode is 'XXX'). Instead of this error-message i am
getting a standard message in the browser: something like 'an exception
occured: CBuilderObject.setAnsiCodePage'
###
#include "MYOBJECTIMPL.H"
STDMETHODIMP TmyObjectImpl::setAnsiCodePage(BSTR _ansicodepage) {
try {
if (wcscmp(_ansicodepage, L"XXX") == 0) {
throw Exception("Ansicodepage is XXX");
}
ansicodepage = AnsiString(_ansicodepage);
} catch(Exception &e) {
return Error(e.Message.c_str(), IID_ImyObject);
}
return S_OK;
}
###
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 23, 2004 5:29 pm Post subject: Re: Exception handling |
|
|
"Marcel" <geenspam (AT) hottentottententententoonstellingen (DOT) com> wrote
| Quote: | I was asking myself why this exception does not print out
'Ansicodepage is XXX' in the users browser whenever
the method is called like CBuilderObject.setAnsiCodePage
"XXX" from the ASP page (so _ansicode is 'XXX').
|
Because it is not supposed to. That is not how things work.
Does your ASO support the ISupportErrorInfo interface, by chance?
Gambit
|
|
| Back to top |
|
 |
Marcel Guest
|
Posted: Thu Sep 23, 2004 7:17 pm Post subject: Re: Exception handling |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Marcel" <geenspam (AT) hottentottententententoonstellingen (DOT) com> wrote in
message
news:41529107 (AT) newsgroups (DOT) borland.com...
I was asking myself why this exception does not print out
'Ansicodepage is XXX' in the users browser whenever
the method is called like CBuilderObject.setAnsiCodePage
"XXX" from the ASP page (so _ansicode is 'XXX').
Because it is not supposed to. That is not how things work.
Does your ASO support the ISupportErrorInfo interface, by chance?
Gambit
|
Hi Gambit,
Sorry i am still a beginner. I don't know the ISupportErrorInfo interface
and really i do not know how to implement it in my ASO.
If it isn't hard to implement can you give me a short explanation of it. I
want to help the users of my ASO with errormessages that make sens so it can
help them to debug theirs ASP scripts.
Marcel
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 23, 2004 9:16 pm Post subject: Re: Exception handling |
|
|
"Marcel" <info (AT) xxxremovethisxxxmediaquest (DOT) nl> wrote
| Quote: | Sorry i am still a beginner. I don't know the ISupportErrorInfo
interface and really i do not know how to implement it in my ASO.
|
Simply add ISupportErrorInfoImpl to the list of classes that your ASO
implementation class derives from.
| Quote: | If it isn't hard to implement can you give me a short explanation of it.
|
ISupportErrorInfo Interface
http://msdn.microsoft.com/library/en-us/automat/htm/chap11_2fqd.asp
| Quote: | I want to help the users of my ASO with errormessages that make
sens so it can help them to debug theirs ASP scripts.
|
It is not your responsibility to display errors. It is the responsibility
of the scripts to query your ASO for any error info they need. In my own
ActiveX objects, I simply expose a LastErrorMsg property that returns the
last message string that was passed to Error().
In the case of ASO, languages such as VBScript have a built-in global Error
object that can return information about the last error that occured in an
ActiveX object, via the IErrorInfo interface, which ISupportErrorInfo helps
provide access to. LAst I checked, Borland already implements IErrorInfo in
its ActiveX objects, but not ISupportErrorInfo.
Gambit
|
|
| Back to top |
|
 |
Marcel Guest
|
Posted: Fri Sep 24, 2004 9:50 am Post subject: Re: Exception handling |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> schreef in bericht
news:41533d1d$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Marcel" <info (AT) xxxremovethisxxxmediaquest (DOT) nl> wrote in message
news:4153214d$1 (AT) newsgroups (DOT) borland.com...
Sorry i am still a beginner. I don't know the ISupportErrorInfo
interface and really i do not know how to implement it in my ASO.
Simply add ISupportErrorInfoImpl to the list of classes that your ASO
implementation class derives from.
If it isn't hard to implement can you give me a short explanation of it.
ISupportErrorInfo Interface
http://msdn.microsoft.com/library/en-us/automat/htm/chap11_2fqd.asp
I want to help the users of my ASO with errormessages that make
sens so it can help them to debug theirs ASP scripts.
It is not your responsibility to display errors. It is the responsibility
of the scripts to query your ASO for any error info they need. In my own
ActiveX objects, I simply expose a LastErrorMsg property that returns the
last message string that was passed to Error().
In the case of ASO, languages such as VBScript have a built-in global
Error
object that can return information about the last error that occured in an
ActiveX object, via the IErrorInfo interface, which ISupportErrorInfo
helps
provide access to. LAst I checked, Borland already implements IErrorInfo
in
its ActiveX objects, but not ISupportErrorInfo.
Gambit
|
Ok thanks Gambit, so your LastErrorMsg property contains the last
errormessage? I.e.?:
STDMETHODIMP TmyASOImpl::myMethod(int x) {
try {
if(x > 100) {
LastErrorMsg = "x is higher than 100";
}
}
} catch(Exception &e) {
return Error(e.Message.c_str(), IID_ImyASO);
}
return S_OK;
}
Oh no sorry i am sure that is not what you meant....
Marcel
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Sep 24, 2004 4:41 pm Post subject: Re: Exception handling |
|
|
"Marcel" <sorryafraidofspam (AT) nospam (DOT) com> wrote
| Quote: | Ok thanks Gambit, so your LastErrorMsg property
contains the last errormessage? I.e.?:
|
That is not how I implement it. I replace calls to Error() with calls to a
custom method that records the error message into a member variable of the
class, then the property simply returns that value.
class TmyASOImpl
{
private:
AnsiString FLastErrorMsg;
};
STDMETHODIMP TmyASOImpl::DoError(const AnsiString& Msg)
{
FLastErrorMsg = Msg;
return Error(Msg.c_str(), IID_ImyASO);
}
STDMETHODIMP TmyASOImpl::get_LastErrorMsg(BSTR *Value)
{
try
{
*Value = WideString(FLastErrorMsg).Detach();
}
catch(const Exception &e) {
return Error(e.Message.c_str(), IID_ImyASO);
}
return S_OK;
}
STDMETHODIMP TmyASOImpl::myMethod(int x)
{
try
{
if(x > 100)
throw Exception("x is higher than 100");
}
catch(const Exception &e) {
return DoError(e.Message);
}
return S_OK;
}
Gambit
|
|
| Back to top |
|
 |
Marcel Guest
|
Posted: Sat Sep 25, 2004 7:31 pm Post subject: Re: Exception handling |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Marcel" <sorryafraidofspam (AT) nospam (DOT) com> wrote in message
news:4153edd4$1 (AT) newsgroups (DOT) borland.com...
Ok thanks Gambit, so your LastErrorMsg property
contains the last errormessage? I.e.?:
That is not how I implement it. I replace calls to Error() with calls to
a
custom method that records the error message into a member variable of the
class, then the property simply returns that value.
class TmyASOImpl
{
private:
AnsiString FLastErrorMsg;
};
STDMETHODIMP TmyASOImpl::DoError(const AnsiString& Msg)
{
FLastErrorMsg = Msg;
return Error(Msg.c_str(), IID_ImyASO);
}
STDMETHODIMP TmyASOImpl::get_LastErrorMsg(BSTR *Value)
{
try
{
*Value = WideString(FLastErrorMsg).Detach();
}
catch(const Exception &e) {
return Error(e.Message.c_str(), IID_ImyASO);
}
return S_OK;
}
STDMETHODIMP TmyASOImpl::myMethod(int x)
{
try
{
if(x > 100)
throw Exception("x is higher than 100");
}
catch(const Exception &e) {
return DoError(e.Message);
}
return S_OK;
}
Gambit
|
Ok Gambit, thanks a lot for your help again! So this way sense-making error
messages can be displayed in the users browser?
Marcel
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun Sep 26, 2004 11:09 am Post subject: Re: Exception handling |
|
|
"Marcel" <info (AT) xxxremovethisxxxmediaquest (DOT) nl> wrote
| Quote: | Ok Gambit, thanks a lot for your help again! So this way
sense-making error messages can be displayed in the
users browser?
|
Not in the standard fashion, no. You would have to display it manually, ie:
On Error Resume Next
//...
myASO.myMethod 150
If Err.Number <> 0 then
Response.Write "An Error Occured: " & myASO.LastErrorMsg
End If
If you support ISupportErrorInfo and IErrorInfo, then the ASP code should be
able to recognize and handle the error automatically.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|