在这里看到:The proper way to do exception handlingIntellij:通过IDE创建一个随机数用作错误号/错误代码?
说这个代码:
function changeBookAuthor(int $id, string $newName){
if(!$newName){
throw new MyAppException('No author name was provided');
}
$book = Books::find($id);
if(!$book){
throw new MyAppException('The provided book id could not be found');
}
//..
}
我想改变这种状况到:
function changeBookAuthor(int $id, string $newName){
if(!$newName){
throw new MyAppException('No author name was provided', <SOMEVERYRANDOMNUMBER>);
}
$book = Books::find($id);
if(!$book){
throw new MyAppException('The provided book id could not be found', <SOMEVERYRANDOMNUMBER>);
}
//..
}
的IntelliJ能帮助我在选择随机数?
它需要是一个静态数字 eg 1234或543535,任何东西。但不是代码! – Toskan
我不知道你的意思是静态数 –
比较'random.nextInt(10)'和'2352'你能发现一个区别吗?一个是代码,另一个是运行时的常数 – Toskan