Access Vialotation

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Feb 27 07:56:21 PST 2009


On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu <quian.xu at stud.tu-ilmenau.de> wrote:
> Hi All,
>
> Is there any way to keep program alive, when an AV takes place?
>
> -- demo -------------------------------
> module NullPointerExceptionTest;
>
> class Foo {
>  void bar() {}
> }
>
> void main() {
>  Foo foo; // foo is still NULL
>  try {
>    foo.bar(); // A NullPointerException will be thrown
>  }
>  catch (Exception E) {
>    // Can I catch this NullPointerException?
>  }
> }
> ----------------------------------------
>
> The program will crash, when the line "foo.bar()" is executed, even when a
> try-catch-block is added. So far as I know, Java and Delphi can prevent
> such kind of crashes from happening with a try-catch-block. Is it possible
> in D?

It's possible on Windows in D, but that's because Windows reports
segfaults with the same mechanism that D uses for exceptions.  Since
Linux (and many other Posix systems) uses signals, it's probably very
tricky to implement in a cross-platform manner.


More information about the Digitalmars-d-learn mailing list