Default Constructor on exceptions not recognised

Issue #1328 resolved
Justin Julicher created an issue

When you have an exception:

public class MyException extends Exception {
      public Integer statusCode {get; set;}
      public String message {get; set;}
      public MyException(Integer statusCode, String message){
          this.statusCode = statusCode;
          this.message = message;
      }
}

you can call this exception with just:

throw new MyException('My Message');

However, in IC it’s saying this is invalid although this compiles and saves.

Comments (2)

  1. Scott Wells repo owner

    I could swear that I implemented some special handling for this given how Apex Exception constructors behave. I'll take a look...

  2. Scott Wells repo owner

    This is obviously quite old, but I'm unable to reproduce this behavior with the following:

    public with sharing class Issue1328Exception extends Exception
    {
        private Integer statusCode { get; set; }
        private String message { get; set; }
    
        public Issue1328Exception(Integer statusCode, String message)
        {
            this.statusCode = statusCode;
            this.message = message;
        }
    
        public static void testIt()
        {
            throw new Issue1328Exception('My Message');
        }
    }
    

    If you still see this behavior, please reopen with any details on how you're reproducing it.

  3. Log in to comment