On 10/10/20 5:12 AM, DMon wrote:
Is there a list of a list of the exceptions or what can be used with catch?

I'm thinking that I missed it and there is something easier than breaking old code, scouring the site, or hypnotic regression.

Only Throwable and classes that are derived from it can be thrown and caught.

It has two decendants:

   Throwable
    /     \
 Error   Exception

Throwable and Error are caught very rarely in special situations. For example, a thread may catch all types of exceptions to report the reason why it's about to die.

So the only type that is and should be used in most programs is Exception:

void main() {
  try {
    foo();

  } catch (Exception e) {
    writefln!"Something bad happened: %s"(e.msg);

    // You can continue if it makes sense
  }
}

So, programs base their exceptions on Exception:

class MyException : Exception {
  this(int i) {
    import std.format;
    super(format!"Bad int happened: %s"(i));
  }
}

void foo() {
  throw new MyException(42);
}

void main() {
  foo();
}

There are helpers in std.exception e.g.

class MyException : Exception {
  import std.exception;
  mixin basicExceptionCtors;
}

void foo() {
  throw new MyException("a problem happened");
}

void main() {
  foo();
}

I have some basic information here:

  http://ddili.org/ders/d.en/exceptions.html

Ali
  • List of exceptions? DMon via Digitalmars-d-learn
    • Re: List of exceptio... Ali Çehreli via Digitalmars-d-learn
      • Re: List of exce... DMon via Digitalmars-d-learn
        • Re: List of ... Ali Çehreli via Digitalmars-d-learn
          • Re: List... DMon via Digitalmars-d-learn
            • Re:... Ali Çehreli via Digitalmars-d-learn
              • ... DMon via Digitalmars-d-learn
                • ... Ali Çehreli via Digitalmars-d-learn
                • ... DMon via Digitalmars-d-learn
                • ... Imperatorn via Digitalmars-d-learn
                • ... Dominikus Dittes Scherkl via Digitalmars-d-learn
                • ... DMon via Digitalmars-d-learn

Reply via email to