digitalmars.D.learn - Access Vialotation
- Qian Xu <quian.xu stud.tu-ilmenau.de> Feb 27 2009
- Qian Xu <quian.xu stud.tu-ilmenau.de> Feb 27 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Feb 27 2009
- BCS <ao pathlink.com> Feb 27 2009
- downs <default_357-line yahoo.de> Feb 28 2009
- Christopher Wright <dhasenan gmail.com> Feb 28 2009
- BCS <none anon.com> Feb 28 2009
- Qian Xu <quian.xu stud.tu-ilmenau.de> Mar 03 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Feb 27 2009
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?
Best regards
--Qian
Feb 27 2009
On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu <quian.xu stud.tu-ilmenau.de> wrot= e:Hi All, Is there any way to keep program alive, when an AV takes place? -- demo ------------------------------- module NullPointerExceptionTest; class Foo { =A0void bar() {} } void main() { =A0Foo foo; // foo is still NULL =A0try { =A0 =A0foo.bar(); // A NullPointerException will be thrown =A0} =A0catch (Exception E) { =A0 =A0// Can I catch this NullPointerException? =A0} } ---------------------------------------- The program will crash, when the line "foo.bar()" is executed, even when =
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 possibl=
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.
Feb 27 2009
Reply to Jarrett,On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Hi All, Is there any way to keep program alive, when an AV takes place?
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.
you can have a posix signal handler throw an exception (I have done it and had it work) but I have no idea if it is supported.
Feb 27 2009
BCS wrote:Reply to Jarrett,On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Hi All, Is there any way to keep program alive, when an AV takes place?
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.
you can have a posix signal handler throw an exception (I have done it and had it work) but I have no idea if it is supported.
Feb 28 2009
downs wrote:BCS wrote:Reply to Jarrett,On Fri, Feb 27, 2009 at 9:01 AM, Qian Xu <quian.xu stud.tu-ilmenau.de> wrote:Hi All, Is there any way to keep program alive, when an AV takes place?
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.
and had it work) but I have no idea if it is supported.
So you can use the signal handler to print a stack trace and maybe some context, but throwing an exception that you then catch is dangerous.
Feb 28 2009
Hello downs,BCS:you can have a posix signal handler throw an exception (I have done it and had it work) but I have no idea if it is supported.
That would match with what I needed: poor man's stack tracing int EveryFunction() { scope(failure) writef("%s:%s\n",__FILE__,__LINE__); ... }
Feb 28 2009
BCS wrote:Hello downs,BCS:you can have a posix signal handler throw an exception (I have done it and had it work) but I have no idea if it is supported.
That would match with what I needed: poor man's stack tracing int EveryFunction() { scope(failure) writef("%s:%s\n",__FILE__,__LINE__); ... }
it does not work with gdc. d2.0 does not have problem with NullPointerException at all. -- Xu, Qian (stanleyxu) http://stanleyxu2005.blogspot.com
Mar 03 2009
On Fri, Feb 27, 2009 at 2:31 PM, BCS <ao pathlink.com> wrote:you can have a posix signal handler throw an exception (I have done it and had it work) but I have no idea if it is supported.
Yeah, that seems dubious to me. I don't know what kinds of guarantees, if any, the signal handler has as to what thread it's called in (if any) etc.
Feb 27 2009









Qian Xu <quian.xu stud.tu-ilmenau.de> 