apex Salesforce中的自定义异常消息

apex Salesforce中的自定义异常消息,salesforce,apex-code,visualforce,apex,Salesforce,Apex Code,Visualforce,Apex,我想创建一个自定义异常。在这个异常中,我想创建一个构造函数,它接受一个字符串参数并附加在getMessage中。如何实现这一点 public class TimelineException extends Exception{ private String message; public override String getMessage(){ return 'Not able to post to Timeline.getting response from Api

我想创建一个自定义异常。在这个异常中,我想创建一个构造函数,它接受一个字符串参数并附加在
getMessage
中。如何实现这一点

 public class TimelineException extends Exception{
  private String message;
    public override String getMessage(){
      return 'Not able to post to Timeline.getting response from Api : '+ message;
    }
  }
我面临的主要问题是,当我使用此选项时:

public TimelineException(Sting x){
}
那就给我一个错误

保存错误:已定义系统异常构造函数:(字符串)gmiror.cls/Google Salesforce Integration/src/classes


您不需要实现某些东西。只需创建一个扩展salesforce异常类的异常类

公共类CommonException扩展异常{}
然后将其用作其他异常类

试试看{
抛出新的公共异常(“测试公共异常”);
}捕获(公共例外){
调试(例如getMessage());
}
控制台输出:


09:18:55:059用户调试[4]|调试|测试常见异常

您可以在控制器中使用类似的功能:

try
{
    'content of what you tring to do'
}
catch(Exception e)
{
     system.debug(e.getStackTraceString());
     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'special friendly message to user'));
} 

然后在visualForce页面中写下apex:messages/您希望消息显示的位置

。您可以来到新网站了解salesforce特定的问题。