It appears I cannot throw exception in async methods:
void Start ()
{
ReadAndThrow(null);
}
public static async Task ReadAndThrow(string path)
{
if(string.IsNullOrEmpty(path) == true)
{
Debug.Log("Wrong");
throw new Exception("Wrong");
}
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs, Encoding.UTF8))
{
string line = null;
while ((line = await reader.ReadLineAsync()) != null) { }
}
}
}
With this, I can see the debug but the exception does not print in the console. It does stop the application, basically, the exception happens but is not printed in the console.
I can use a try catch and print the error, but why is the exception omitted from console? It does not show in the error section, I checked I would miss it from there.
How could I get the exception to print?
EDIT:
Latest used code, not printing:
async Task Start()
{
await ReadAndThrow(null);
}
async Task ReadAndThrow(string path)
{
Debug.Log("Start");
try
{
if (string.IsNullOrEmpty(path) == true) { Debug.Log("Wrong"); throw new Exception("Wrong in"); }
}catch(Exception e)
{
Debug.Log("Method" + e.Message);
throw;
}
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs, Encoding.UTF8))
{
string line = null;
while ((line = await reader.ReadLineAsync()) != null)
{
}
}
}
}