Flooding used to be a much bigger problem in the Western United States and it was solved with dams. Yes, there is thd risk of dam failure but we're weighing up the real and present risk of flooding regardless against the possible risk of dam failure.
Unfortunately, there has been increasing opposition from the environmental lobby against building dams in the developing world in recent decades (eg [1]) and this matters when such countries are usually dependent on the World Bank and/or IMF to fund their construction.
Dams not only reduce the risk of extreme flooding but also provide cheap hydroelectric power, which is of incredible value to a developing nation.
Pakistan has some dams but clearly not enough. Given these extreme events that led to this catastrophic flooding are increasingly common and that no action in climate change will change this in the short or even medium term, it's time to build dams. Lots of them.
[1]: https://www.theguardian.com/global-development-professionals...