Intellij idea Intellij:通过IDE创建一个随机数用作错误号/错误代码?
请看这里: 请说出以下代码:Intellij idea Intellij:通过IDE创建一个随机数用作错误号/错误代码?,intellij-idea,Intellij Idea,请看这里: 请说出以下代码: 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 n
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>);
}
//..
}
函数changeBookAuthor(int$id,字符串$newName){
如果(!$newName){
抛出新的MyAppException('未提供作者姓名',);
}
$book=Books::find($id);
如果(!$book){
抛出新的MyAppException('无法找到提供的图书id',);
}
//..
}
intellij能帮我选择随机数吗 我个人使用不同类型的异常,而不是异常代码 例如:
try{
...
} catch (PDOException e1){
// Show a message that we could not do SQL work
} catch (NumberFormatException e2){
// Show a message that input was not a valid number
} catch (Exception e){
// I'm not sure what was wrong but definitely there was some thing wrong
}
但是如果您仍然需要随机数,请转到,这里有一些数字生成器,复制值并将它们定义为代码中的常量(我猜您使用的是PHP)每次打开网站都有点乏味,不是吗?我害怕有时间写我自己的插件。。。