Re: Structured exception information



Stephen Leake wrote:

How can I pass some error information from the constructor function
out, so that it's used when the exception is handled?

Why do you want to?

So that the handler has more information about the error?

Generally, all you can do is report the error to
the user.

That's what I want to do.

Can you give a detailed example of passing more complex information
that is actually used?

Imagine a constructor function that calls a database or a script engine with the query/script provided as a parameter. Some error can result and I want to raise an exception. The handler might benefit (even if for the purpose of presenting a nice error pop-up message) from:

- error code
- error message
- line number
- character position
- hint from the engine
- timestamp from within the engine
- ...

Another example - imagine that your compiler just prints "COMPILER_ERROR" instead of everything that it actually prints.
That wouldn't be very funny!

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
.



Relevant Pages

  • Re: Structured exception information
    ... I want to raise an exception. ... The handler might benefit (even if for the ... purpose of presenting a nice error pop-up message) from: ... timestamp from within the engine ...
    (comp.lang.ada)
  • Re: try/catch block design. Two approaches, which ones best?!
    ... It is about preserving the *original* stack trace, ... trace that only goes as far as your handler; ... Imagine the exception is thrown 27 levels down, and you catch it at the 15th ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Try Finally...
    ... Now we can protect every more or less specialized action ... an error indication (exception or error code) has to be ... an according exception handler can be inserted into the code. ... resources, as they are related to specific actions. ...
    (comp.lang.pascal.delphi.misc)
  • Re: WinForms bug? ThreadException not invoked on Exceptions in system code pre-processing the me
    ... Message Queue and invoking the appropriate handler. ... if an Exception is raised during the PRE-PROCESSING of a Windows ... And because any handling will probably fail if there is no memory, the CLR will terminate the application without attempting to call the ApplicationException or UnhandledException events. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: BackgroungWork taske ended for no appearent reason
    ... To do the same thing with Try/Catch blocks requires wrapping every file access with a Do While ... ... If there was any exception thrown in your DoWork event handler, ... If the operation raises an exception that your code does not handle, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)